A heat engine typically uses energy provided in the form of heat to do work and then exhausts the heat which cannot be used to do work. Thermodynamics is the study of the relationships between heat and work. The first law and second law of thermodynamics constrain the operation of a heat engine. The first law is the application of conservation of energy to the system, and the second sets limits on the possible efficiency of the machine and determines the direction of energy flow.
Heat engines such as automobile engines operate in a cyclic manner, adding energy in the form of heat in one part of the cycle and using that energy to do useful work in another part of the cycle.