A Stirling engine is a type of heat engine that operates by cyclically compressing and expanding air or other gas, resulting in a controlled conversion of heat energy to mechanical work. It is a closed-cycle regenerative heat engine with a permanently gaseous working fluid. The engine is typically sealed, with all parts enclosed in the same cylinder. A Stirling engine can be used to generate electricity, but is more commonly used as a mechanical device, such as a pump or a generator.