How to constrain a node within a square

Godot Version

4.2

Question

I want to constrain a node2D"s position within an area, like clamp, but between the sides of a square

it can either be achieved by programmatically calculate its position and width height and put it inside a clamp like
image
above just shows how it restricts the movement until the screen size, didnt calculate the width/height in it

or
actually put collision shape that act like a wall to make it contained between specified area, but this also will need the “node2D” to have collision shape, usually like characterbody2d