Look at the kinetic theory model for gases, say ideal gases, where they are merely billiard balls. If you put the gas into a cylinder with piston, then the additional energy that the gas receives when you compress the gas is given from the gas hitting the moving piston and bounces back with more speed than it had before the collision. This is the work being done. Now by the same token, when you pull out the piston, the piston will steal energy from the bouncing particles, having work done on it. There is a problem with the pull though. If you pull on the piston soooooo fast that no molecule ever touches it, and you expand the volume by, say, a factor of two, then you have changed the state without changing the energy. If you were to then compress back to the original volume, it would have a lot more energy than it did initially. So, the action of 'pulling' the piston must move at a very slow rate when compared to the motion of the molecules if you want it to be reversible.
I made it sound like this only happens for a pull, but that is not true. If you were to push the piston in, only at times where the particles are NOT touching the piston, you could do the same with pushing - i.e. change volume without changing energy.
Edit: There is a neat program written for vpython (visual python), that demonstrates this nicely. They have the temperature of the gas given, and then a bunch of balls zinging around in a cylinder, then you move the piston up and down, etc. But all of the quantities are simulated, and not calculated. And you can pull the piston faster than the speed of the balls and 'pump up' the temperature. It is a really cool demo. Ruth Chabay, and Bruce Sherwood came up with the simulation if I remember correctly.