The invention provides methods and compositions for treating viral infections. A nuclease is used to cleave viral nucleic acid in an infected cell. The nuclease cleaves viral nucleic acid in a sequence-specific manner and thus does not cleave genes or other important genomic features from a genome of the infected host. In a preferred embodiment, the nuclease is a CRISPR-associated protein such as Cas9 and is delivered to the infected cells as a ribonucleoprotein that includes the Cas9 and a guide RNA designed to target HSV or CMV nucleic acid. Additionally or alternatively, the nuclease can be delivered encoded on a plasmid or as mRNA to be expressed within the target cells. Methods and compositions may be used to treat a patient or may be used to treat tissues, cells, or organs ex vivo.