C# Keep Character Controller Within Gameobject edge Boundaries

I have a character controller that is standing on top of a gameobject cube. I would to like to keep the character controller from going over the cube’s edge boundaries. Is there a value I could check to see if the controller is near or going over the cube’s edge boundaries? I want this to function like an invisible collider turned inside out, keeping everything inside rather than push it away.
1869741--120132--screen.png

The easiest - and probably best solution - would be to just put four cube colliders around your ground.