You can do something like this:
Sprite1.X<Sprite2.BBoxLeft+Sprite1.Width/2--->Sprite1 Set X to Sprite2.BBoxLeft+Sprite1.Width/2
Just add 3 more conditions for right, top, bottom with appropriate values.
One event with two actions will do:
every tick
sprite1 set x = clamp(sprite1.x,sprite2.bboxleft+0.5*sprite1.width, sprite2.bboxright-0.5*sprite1.width)
sprite1 set y = clamp(sprite1.y,sprite2.bboxtop+0.5*sprite1.height, sprite2.bboxbotto-0.5*sprite1.height)