You could do something like this:
Create 2 variables:
PlayerLastX
PlayerLastY
Every Tick:
If PlayerSprite touches SandSprite Set PlayerLastX to Player.X and PlayerLastY to Player.Y
Every Tick:
If PlayerSprite is not touching Sand Sprite:
Set Player position to PlayerLastX & PlayerLastY so that it remains on the SandSprite and can still move where it came from.