I haven't tried it, but you can make the border of the box solid. (Add an invisible solid rectangular sprites to each side, pin everything together)
When there is no user input, pin the ball to the box. When user presses a key to move the ball, unpin it and let the 8-behavior take care of it.