Interstellar space is not actually empty, but is filled with astronomical debris. Supernovae in particular, but also stellar winds, comets and asteroids, all disperse material into the interstellar medium (ISM) as a result of explosions, collisions or the normal ejection of material. In the case of ejecta from a star, the nature of the material depends on the nucleosynthesis taking place in that star and on the nature of the ejection (supernovae or stellar winds). Nevertheless, in most stellar ejecta, there is an abundance of carbon, hydrogen and oxygen, as well as nitrogen, sulphur and phosphorus - in the form of carbon monoxide, oxides, carbon grains and even organic molecules such as cyanopolyacetylenes and polycyclic aromatic hydrocarbons (PAHs).
This debris floats through space, perhaps combining with the hydrogen and helium left over from the big bang to form dense molecular clouds, or sometimes just remaining as solitary molecules, thereby becoming part of what is known as the diffuse ISM.
Space is a pretty harsh environment, however, and many of the molecules in the diffuse ISM are quickly destroyed as a result of ultraviolet (UV) photolysis (in the case of gaseous molecules) and through erosion, vaporisation and shattering by interstellar shock waves (in the case of the solid grains). Dense molecular clouds provide greater protection to their constituent particles, enabling them to survive longer. In fact, in this environment the energy from cosmic shock waves and the UV light that radiates from background stars causes constructive reactions. And with molecules containing carbon, hydrogen, nitrogen, oxygen, sulphur and phosphorus mixing together in the cloud, the conditions are right for the creation of increasingly complex organic molecules.