To start, viruses are generic material wrapped in proteins. The functionality of proteins depends on their shapes and the environment strongly affects the shape of a protein. Viruses that exist on Earth have proteins that are stable on Earth. A virus that comes from a different environment would be liable to fall apart on the Earth. RNA itself is pretty unstable by itself (hence why cells use DNA), but there are plenty of viruses that use it as their genetic material.
Infecting host cells is another matter. Viruses are generally pretty specific with their host cells. They enter host cells by binding to specific proteins on their surfaces. Once inside they take advantage of the specific cellular machinery present. For example, the polio virus has a single strand of RNA that codes for a single long polypeptide that is then sliced at specific point by host enzymes to produce the final viral proteins. Some viral proteins act to suppress the defenses of the cell and the immune system in general. An alien virus would be insanely lucky to be able to infect local life at all, let alone reproduce and spread. Unless life across the universe is incredibly similar.
Given these thoughts, it seems like it would be more likely for viruses to spontaneously form on Earth than another planet (or interstellar space). Viruses forming on Earth would have the advantage of starting with organic materials that already work with existing life. The Earth is generally protected from harsh radiation and extreme temperatures. The most important thing is that any forming viruses would have immediate (relative to crossing space) contact with host cells to infect and evolve.
The only reason it wouldn't be happening on Earth is if the Earth is completely unsuitable for it. Even if both are happening, the vast distances and harsh nature of space should shift the equilibrium strongly towards native viruses. But if the Earth is unsuitable for it then how are viruses able to survive and reproduce on a planet that's so unsuitable for them?