The short answer is that it “travels” via radiation.
The long answer entails a very short course in heat transfer 101. There are three basic modes of heat transfer:
Conduction,
Convection, and
Radiation.
Conduction requires direct contact. That is, heat travels either through a solid object, or between two solid objects in direct contact. When you put a pan on the heating element of an electric stove, or stick your tongue to a cold lamppost in the winter, you are transferring heat through conduction.
Convection travels through a fluid. For example, when you step into a hot-tub or blow on your hot coffee you are using convection.
Both conduction and convection require some form of direct contact, and the heat travels from molecule to molecule.
Radiation transmits through a vacuum. Any wavelength in the electromagnetic spectrum is capable of transmitting (or absorbing) energy, which often becomes heat in the object absorbing the radiation. We absorb heat from sunlight primarily in the infra-red range. A microwave oven transmits in, wait for it … the microwave range.
That’s how heat travels through space.