You never want to use the mouse coordinates directly if you want to limit the area it'll be in because you'd have to use the POSITION MOUSE command which will cause problems and weird glitches. You always want the mouse to have free reign on the whole screen.
Instead you want to use variables to store the current mouse coordinates and have a set of IF/THEN statements to change the coordinates if they go beyond where you want them to be.
Also it's better to do the screen and character setup before the main DO/LOOP. It's not a good idea to create, use once, and delete images when you're just going to create the same image in a few milliseconds.
Set Display Mode 640, 480, 32
Hide Mouse
` Setup screen
Box 10, 0, 15, 480
Box 625, 0, 630, 480
Box 0, 10, 640, 15
Box 0, 465, 640, 470
get image 100,0,0,640,480,1
` Setup ship
Box 315, 235, 325, 245
Get Image 1, 315, 235, 325, 245,1
Do
` Show the background
paste image 100,0,0
` Make the ships coordinates the same as the mouse
ShipX=mousex()
ShipY=mousey()
` Limit ships area
if ShipX<15 then ShipX=15
if ShipY<15 then ShipY=15
if ShipX>615 then ShipX=615
if ShipY>455 then ShipY=455
` Show the ship
Sprite 1,ShipX,ShipY,1
Text 30, 50, "ShipX position = " + str$(ShipX)
Text 30, 70, "ShipY position = " + str$(ShipY)
Text 30, 110, "Mouse x position = " + str$(mousex())
Text 30, 140, "Mouse y position = " + str$(mousey())
Loop