Heat flow is independent to medium, therefore energy can flow in all kinds of container. Energy can also flow in vacuum. BTW, energy can be flow from higher temperature to lower temperature, so even satisfying only this principle is sufficient. If you want basis, it is the zeroth law of thermodynamics.