Hi Federico,
As per my understanding, you are developing a script to analyze the motion of a quadratic object inside a box, that is pushed out with a spring. If the wall reaction is strong, the object bounces, otherwise it breaks the wall and the model fails.
In the Simulink Library browser go to Simscape > Multibody. Model the bodies of an articulated mechanical assembly. Refer the following documentation to understand how to select the correct blocks and tweak their physical bodies for your requirement:
You can refer the following article to model the contact forces between two solids:
Hope this helps.
Regards
Ninad