The important parts of a basic gun are barrel, bullet, ammo casing, primer and gun powder. When the gun’s trigger is pulled, the igniter or primer ignites the gun powder, which explodes and pushes the bullet towards a small piston. As the bullet moves towards the piston, the air in the barrel and cylinder is compressed which increases the pressure on the piston. The piston compresses against a spring which increases the pressure. When this pressure reaches a particular point, the bullet stops and the whole process reverses. The reversal process thus pushes the bullet out of the barrel with a torque that is a hundreds times higher than the piston pressure.
The gun engine also works almost on the same principle. However, in a gun engine, the cylinder resembles a gun, the bullet resembles a piston, the primer resembles the igniter, and the combustion chamber resembles the ammo casing.

click to enlarge