Power ratchet wrenches, whether they are pneumatic or cordless, work in very much the same way. They typically have a motor that runs at a high RPM and in one direction only, regardless of tightened or loosened nut. The output of the motor goes through planetary gearing, which reduces the speed and increases the torque, typically by a gear ratio of between 4:1 and 6:1. The output of the gearing drives a crankshaft with an offset pin on the end of it. This offset pin swings a yoke that is constrained to move from side to side only. So one complete turn of the crankshaft swings the yoke from one side to the other and back again. If you think of a manual ratchet, where you repeatedly swing the handle back and forth – the yoke is doing the same thing, just with a short angular stroke and at a much faster rate.
The inside diameter of the yoke is lined with gear teeth that surround and interact with a pawl-based ratcheting mechanism, which is much like in a manual ratchet. When the yoke swings from one side to the other, the teeth lock with the pawl to turn the tool output. And when the yoke swings back, the teeth slip past the pawl without any movement of the tool output. The forward/reverse selector on the tool is used to change the orientation of the pawl so that it either locks with the yoke teeth for clockwise rotation of the tool output or for counter-clockwise rotation.