You might want to adjust Max_x so your sprite stays fully on screen. 800 - sprite width, say.
Then after you decrement your sprite's x position (line #39 in your posted code), make sure it isn't less than Min_x. If it is, set it to equal Min_x. Similar for Max_x. Use the same technique for the vertical axis.
Also, I don't think I'd call setPosition first thing. Just modify the pos.x and pos.y variables in the if statements and then call setPosition once at the end - just before you call window.clear().
Yes because the position you set refers to the top-left corner of the sprite. So if your 'max x' is 800, it'll keep going until it draws the leftmost pixels of your sprite at position 800 - i.e. the whole thing's (just) offscreen.
Sometimes that's what you want (- it means a game character can smoothly exit the screen stage left/right) but if you want to keep your sprite visible at all times modify that max value. For example, if your sprite's 64 pixels wide, maybe: constint Max_x = 800 - 64;
Hope that helps.