Ed Rybicki, a virologist at the University of Cape Town in South Africa, answers:
Tracing the origins of viruses is difficult because they don't leave fossils and because of the tricks they use to make copies of themselves within the cells they've invaded. Some viruses even have the ability to stitch their own genes into those of the cells they infect, which means studying their ancestry requires untangling it from the history of their hosts and other organisms. What makes the process even more complicated is that viruses don't just infect humans; they can infect basically any organism—from bacteria to horses; seaweed to people.
Still, scientists have been able to piece together some viral histories, based on the fact that the genes of many viruses—such as those that cause herpes and mono—seem to share some properties with cells' own genes. This could suggest that they started as big bits of cellular DNA and then became independent—or that these viruses came along very early in evolution, and some of their DNA stuck around in cells' genomes. The fact that some viruses that infect humans share structural features with viruses that infect bacteria could mean that all of these viruses have a common origin, dating back several billion years. This highlights another problem with tracing virus origins: most modern viruses seem to be a patchwork of bits that come from different sources—a sort of "mix and match" approach to building an organism.
The fact that viruses like the deadly Ebola and Marburg viruses, as well as the distantly related viruses that cause measles and rabies, are only found in a limited number of species suggests that those viruses are relatively new—after all, those organisms came along somewhat recently in evolutionary time. Many of these "new" viruses likely originated in insects many million years ago and at some point in evolution developed the ability to infect other species—probably as insects interacted with or fed from them.
HIV, which is thought to have first emerged in humans in the 1930s, is another kind of virus, known as a retrovirus. These simple viruses are akin to elements found in normal cells that have the ability to copy and insert themselves throughout the genome. There are a number of viruses that have a similar way of copying themselves—a process that reverses the normal flow of information in cells, which is where the term "retro" comes from—and their central machinery for replication may be a bridge from the original life-forms on this planet to what we know as life today. In fact, we carry among our genes many "fossilized" retroviruses—left over from the infection of distant ancestors—which can help us trace our evolution as a species.
Then there are the viruses whose genomes are so large that scientists can't quite figure out what part of the cell they would have come from. Take, for instance, the largest-ever virus so far discovered, mimivirus: its genome is some 50 times larger than that of HIV and is larger than that of some bacteria. Some of the largest known viruses infect simple organisms such as amoebas and simple marine algae. This indicates that they may have an ancient origin, possibly as parasitic life-forms that then adapted to the "virus lifestyle." In fact, viruses may be responsible for significant episodes of evolutionary change, especially in more complex types of organisms.
At the end of the day, however, despite all of their common features and unique abilities to copy and spread their genomes, the origins of most viruses may remain forever obscure.