Over the past year, the Zika virus has threatened millions of people throughout South and Central America, posing a risk of serious birth defects among a generation of newborn children. Officials in warm, mosquito-rich regions of the United States—such as Texas, Louisiana, and Florida—are scrambling to track the disease and keep it from spreading; the appearance of Zika in Miami last August prompted a two-month federal travel advisory for pregnant women.

Controlling the spread of viruses like Zika is the kind of centralized, coordinated responsibility that governments were created to address. Yet the process for preventing deadly epidemics remains antiquated at best. First, people must feel sick enough to go to a doctor. Next, the physician must make an accurate diagnosis. And finally, the results must make their way to the country’s central health authority, where the risk of a general outbreak can be assessed. That’s a huge challenge in parts of the world where doctors are scarce and diagnostic tests can be unreliable. Even in the United States, which has one of the world’s best early-monitoring systems at the Centers for Disease Control, identifying a disease outbreak can take as long as a month. Making matters even worse, some people infected with Zika show no symptoms of the disease, passing the virus to others without even knowing it.

But what if scientists could catch diseases before they sweep through populations, causing untold suffering and death? What if we could identify potential outbreaks before people are even infected? That’s the thinking behind a new scientific partnership being funded by government intelligence agencies: combining James Bond spy-craft and Silicon Valley wizardry to disrupt the fields of entomology and epidemiology.

At Microsoft headquarters outside Seattle, a team of researchers has pulled together top scientists from around the country to develop an early-warning system for plagues—a project that stands to save millions of lives. Known as Project Premonition, the system aims to scrap the current process of disease reporting, which is slow and unreliable. Instead, researchers are trying to deploy digital firepower and drone technology to identify pathogens in real time—not only mosquito-borne viruses like Zika, malaria, and dengue, but infections like Ebola that are transmitted by human blood and bodily fluids.

The effort is being funded by the Intelligence Advanced Research Projects Activity, a government spy program modeled after the military’s DARPA initiative. IARPA is designed to support “high-risk, high-reward” projects to advance the goals of the intelligence community—a skunkworks to help the government find new ways to identify hackers and terrorists. But now, in addition to developing surveillance technology to monitor internet chatter, the government is funding private industry to spy on mosquitoes.

“Insects kind of rule the world,” says Eamonn Keogh, a computer science and engineering professor at the University of California in Riverside who is responsible for one of the project’s biggest breakthroughs. “But nobody had applied computer science to entomology.”

At Project Premonition, Keogh and his fellow scientists have developed a next-gen bug trap: a large black cylinder that emits signals designed to attract mosquitoes. When an insect flies inside one of the trap’s 60 tiny compartments, a sensor runs a complex series of calculations to determine in real time whether the bug is a mosquito, whether it’s the right species and gender (only female mosquitoes bite), and whether it has recently feasted on someone’s blood. If the sensor indicates it has found the right kind of mosquito, a tiny trapdoor snaps shut. Once all 60 compartments are full, a drone fetches the trap and flies it back to a mother ship, where the blood each insect has ingested is rapidly analyzed for markers of disease.

Last spring, when Project Premonition conducted preliminary trials of the system near Houston, things didn’t go quite as planned. The trapdoors malfunctioned, and the lure used to attract the mosquitoes—a combination of smelly socks and dry ice, which mimic our body odor and the carbon dioxide we exhale—is too expensive and labor intensive to replicate on a wide scale. Based on the initial tests, though, the traps could be up and running within the next five years—a reasonable time line for such a complex system.

One element of the traps that has already proved effective is the sensors used to identify insects. When a bug flies past the device—essentially an inexpensive LED beam—its beating wings cause a shadow to appear on the sensor. That shadow is then translated into an acoustic signal that correlates to the high-pitched whine of a mosquito, say, or the low-pitched hum of a bumblebee. But that’s just the first step. Because there are thousands of species of mosquitoes and bees alone, the sound must then be instantly evaluated against millions of data points assembled by Keogh and his team: everything from the location of the trap and the time of day to current weather conditions and field research on insect acoustics. “It takes the insects about one-twentieth of a second to fly past the LED beam,” Keogh says. “And at the end of the one-twentieth of a second, we already know what it is.”

In the field tests, the sensors accurately distinguished mosquitoes from leaves and bees, and even identified mosquitoes of two different species. “It’s fantastic,” says Douglas Norris, a professor of microbiology and immunology at Johns Hopkins University. “This is the first really big step in trapping technology. Using it to identify mosquitoes on the way in is just such a game changer.”

The government is working on other fronts to speed its response to diseases, relying on advanced detection platforms that can recognize as many as 20 pathogens simultaneously and report the results within hours. And as Project Premonition works to get the new disease sentinels up and running, Keogh is looking into other applications for his insect spy system. In agriculture, for example, sensors could let farmers know when and where pests are emerging—allowing them to target small patches with pesticides, rather than blanketing an entire farm with toxic chemicals. The National Science Foundation recently awarded Keogh $3 million to train graduate students in computational entomology, the new field he has created. And Keogh is sending his LED-based insect spy devices to scientific colleagues around the world, so they can collect more data on caged insects to add species to the model.

In the end, such work indicates how Big Data can be used effectively for all kinds of government functions beyond surveillance and law enforcement. The shift, Keogh notes, will disrupt entomology and epidemiology in much the same way that computers transformed the music industry. Music on vinyl was “cumbersome and expensive,” he says. “But once it became a digital object, you could do cool things with it. We’re basically taking insects and making them digital objects.”