What is happening is that he can leave the screen (top, bottom, left or right side). There are a number of ways to fix that. In my experience, the easiest is by using two blocks in the sprites toolbox (red/pink blocks). One is called “create edge sprites”. You can put that one at the very top (or near the top) of your code (not inside the draw loop). The other one needs to go in the draw loop somewhere. It is the “sprite.bounceOff” block. change the word sprite to character in your program and inside the box type “edges”. So, the final result would be character.bounceOff(edges);
The first one creates invisible rectangles (borders), just off the screen. The 2nd one tells your character to bounce off of them if it touches them.
There are other ways if you only want to fix one of the borders, but try that and see if that is what you are after.
Have a good day!
Mike