The evolutionary origins of viruses is disputed. Although they don't leave a fossil record it's known that they are ancient (c. 4.5 billion years old). It's not known, however, whether they evolved from cellular lifeforms, or pre-dated them.
“There are three classical hypotheses on the origins of viruses:
• Viruses may have once been small cells that parasitised larger cells (the degeneracy hypothesis, or reduction hypothesis);
• Some viruses may have evolved from bits of DNA or RNA that “escaped” from the genes of a larger organism (the vagrancy hypothesis, or escape hypothesis);
• Viruses could have evolved from complex molecules of protein and nucleic acid before cells first appeared on earth (the virus-first hypothesis).
None of these hypotheses have ever been fully accepted.”
Note: Another (as yet unproven) theory is that viruses may have evolved away from Earth, arriving here from deep space (part of Panspermia theory.)