Object stops but then eventually breaks through

I am working on a movement code using the left and right keys, and the function rigidbody.MovePosition. When the player collides with walls it at first stops, but then if I hold down the key too long it will fall through the floor or walls eventually. The walls and floor have a box collider and the player has a rigidbody with default settings

function Update () {

if (Input.GetKey ("left"))
		rigidbody.MovePosition(rigidbody.position + Vector3.left * 5 *Time.deltaTime);;
		
if (Input.GetKey ("right"))
		rigidbody.MovePosition(rigidbody.position + Vector3.right *5 *Time.deltaTime`

Use “FixedUpdate()” instead of “Update()” if you’re dealing with an object with a Rigidbody.

FixedUpdate