What parameters determine the acceleration a spacecraft can acquire using the gravity of a celestial body?

Contemporary spacecraft frequently rely upon gravity to accelerate/decelerate. Given a spacecraft already in space - What factors determine the acceleration it can acquire from the gravity of another body? Is there an upper limit to such gravitational acceleration?

-

The acceleration you're describing is known as a gravity assist.

You can get an idea of the maximum acceleration possible by working in your rest frame i.e. the frame in which you're stationary and the planet is approaching you at a speed $v$. If you can arrange to do a half loop round the planet and exit in the opposite direction then you'd leave the planet at a speed relative to the planet of $v$, and because in our frame the planet is moving at a speed $v$ you'd end up travelling at a speed of $2v$.

This is the maximum energy you can extract from the planet's motion, but spaceships we launch from Earth don't use anything like this trajectory. The Earth is already moving around the Sun at around 30km/sec and the probes we launch share this velocity. The hard bit is getting a high velocity in the direction away from the Sun. The gravity assists that our probes use is designed to convert velocity tangential to orbit to velocity away from the orbit, and the acceleration they get is a lot smaller then the ideal case above.

-