Hi cheng,
I understand that you want to model a base excited spring-mass system with the mass constrained to move between 2 walls.
Translational Hard Stop block can be used for modelling the constraint and the base excitation can be provided using an Ideal Translational Velocity Source block.
You can refer to the below model:
You can configure the bounds of the Translational Hard Stop block and other parameters according to your requirements.
Sample Output for a Sinusoidal Excitation: