Consider a system consisting of some quantity of a gas enclosed in a cylinder fitted with a movable, massless and frictionless piston.

During expansion of the gas, molecules colliding with the piston lose momentum to it. This exerts force and hence pressure on the piston, moving it outward through a finite distance. Here, the gas does a positive work on the piston. There is increase in the volume of the gas. The work done by the piston on the gas is negative.
During compression of the gas, molecules colliding with the piston gain momentum from it. The piston moving inward through a finite distance exerts force on the gas. Here, the gas does a negative work on the piston. There is decrease in the volume of the gas.

The work done by the piston on the gas is positive.