Hundreds of millions of years ago, prehistoric viruses inserted their genes into the genomes of our ancestors. They found their way into eggs or sperm, and then into embryos. As they passed down from one generation to the next, they picked up mutations that disabled their ability to infect new cells. Eventually, they became permanent fixtures of our genomes, as much a part of our DNA as our own genes.

Today, these ‘endogenous retroviruses’ or ERVs make up 8 percent of our genome. They are genetic fossils—remnants of our viral ancestors, and records of epidemics past.

ERVs are not passive stowaways. They provided raw material for evolution, in the form of viral genes that our ancestors could tinker with and put to new use. For example, syncytin, a gene that’s essential for creating the placenta, came from a virus; in the words of Carl Zimmer, “If not for a virus, none of us would ever be born.”

ERVs also contain sequences that dictate when and where genes should be switched on. So when they first infiltrate a genome and hop around, they can rapidly and radically re-wire entire networks of genes. Edward Chuong, Nels Elde, and Cédric Feschotte from University of Utah School of Medicine have now found the most dramatic example of this re-wiring. They have shown that some ERVs that have shaped the evolution of our immune system, are now controlling the activity of critical immunity genes.

Which means that we defend ourselves from some viral infections with the repurposed remains of ancient viruses.

When we suffer from infections, two proteins called IRF and STAT coordinate our immune responses. They hover over our DNA, looking for particular sequences that they can stick to. When they find these docking sites, they land and activate nearby genes. And when Chuong looked at these docking sites, he found that many of them came from ERVs. By hopping around our genomes, these viruses created new ports for IRF and STAT, and changed the portfolio of immune genes that they turn on.

The team focused on one of these viruses, known as MER41. It first infected a prehistoric primate between 45 and 60 million years ago, and expanded so profusely that each of us carries more than 7,000 copies of it. And nearly 1,000 of these copies can attract STAT or IRF.

One copy of the MER41 virus sits next to a gene called AIM2. This is an important player within the immune system: It detects when human cells have been infected by certain viruses and bacteria, and forces the cells to self-destruct to stop the infections from spreading. But that doesn’t happen without the MER41 sequence—when Chuong cut it out, he produced human cells that no longer self-destructed in the presence of viruses.

This is the first time anyone has clearly shown that an ERV controls an important immunity gene. It’s unlikely to be the last. Chuong found three more immunity genes that seem to be controlled by MER41 copies, and there are almost certainly more. “We don’t know how extensive the network is,” says Feschotte. “We need to go one by one, testing these genes.”

This pattern isn’t unique to humans. The team found that a different virus had littered the genome of mice with docking stations for STAT. And the MER41 viruses have independently invaded the genomes of many other mammals, including lemurs, bats, mice, cows, and dogs, perhaps affecting the activity of different immune genes in each family. Time and again, it seems that viruses have shaped the evolution of the mammalian immune system—and not just by giving it something to push against, but by giving it new ways of pushing.

It’s the scope of the discovery that’s impressive says Guillaume Bourque from McGill University. While other scientists have shown that ERVs can control the activity of specific genes in specific animals, Chuong has shown that many families of ERVs can influence an entire branch of the immune system in many species. “This really demonstrates that importance that [such sequences] have played, and probably continue to play, in the evolution of mammalian gene regulation.”

Sure, but that leaves one huge mystery: why exactly would a virus contain sequences that act as docking stations for human proteins like STAT, and that can activate nearby human genes.

“That should not come as a surprise to anyone familiar with retroviruses,” says Dixie Mager at the University of British Columbia. Many of these viruses, like HIV, infect immune cells. They could have evolved genetic tricks for manipulating their host’s immune system to boost their own reproduction. The hosts could then have co-opted those same tricks to re-wire their defenses against the viruses! Evolution, it turns out, is really good at irony.