Take a look at:
clamp - http://www.conitec.net/beta/aclamp.htm

Basicly clamp every coordinate (x,y,z) to the specific boundaries.