The next butterfly you see flitting about might just be a genetically modified organism, given genes from a virus that protects it from other viruses. This isn’t the work of scientists trying to save pollinators, but parasitic wasps intent on rendering their hosts defenseless. 

These genetic engineers are braconids, members of a large wasp family that begin their lives inside the bodies of other insects like beetles, flies, aphids, and caterpillars. Many of them get help subduing their hosts from viruses. A female wasp injects her eggs, along with some viral particles, into an insect’s body. The virus—called a bracovirus—messes with the host’s immune system and keeps it from mounting a defense against the eggs. With no resistance from the host’s body, the eggs develop unchecked. When the wasp larvae hatch, they eat their way out of their host. 

A caterpillar’s body is the birthplace for a new generation of wasps, but it’s usually a dead end for bracoviruses. Their new hosts rarely survive their encounters with the wasps, and the viruses can’t replicate themselves like other viruses do. They are, in a way, domesticated, and part of the wasps. They’re produced inside the ovaries of the female wasps and can’t make copies of themselves because some of the genes they need to do that are in the wasps’ own genomes. 

Every once in a while, though, a caterpillar gets lucky. It might get attacked by a wasp that it’s not a compatible host for, or it may interrupt a wasp while she’s laying her eggs. The caterpillar “lives to tell the tale,” as biologist Jean-Michel Drezen puts it, and survives the encounter, but it still has bracoviruses inside it. 

In these cases, Drezen and other scientists have found that something strange can happen (as if wasps churning out domesticated viruses in order to use caterpillars are nurseries for their kids wasn’t weird enough). Genes from the bracoviruses sometimes find their way into the caterpillars’ genomes and get passed down to their offspring. Sometimes this continues for ages—one butterfly Drezen found the viral genes in isn't a host for braconid wasps, but its ancestors were, and the viral genes have persisted in the lineage’s DNA for around five million years. 

The viral genes appear to be repurposed once they’re integrated into the caterpillars’ DNA. While they were once part of a biological attack meant to subdue the caterpillars’ immune systems, they now help the insects resist infection from another group of viruses—the baculoviruses, which attack a variety of butterflies and moths via contaminated leaves. One of the bracovirus genes prevents these other viruses from reproducing, while another one can block the initial infection. Even something as awful as getting attacked by a parasitic wasp, it seems, can sometimes have a silver lining.