Someone made a nice video.
There is a rubber seal around the piston which makes it air-tight with the inside of the cylinder. Then there are two check valves which only let the air flow in one direction: one to allow outside air in when you pull (but not let is out when you push), and one to let the high pressure air inside your tyre (but not let it out).