A couple ideas come to mind. One is to dynamically create some extra walls to help to box fall into the hole. Another is to check if there’s a hole below a box and have it shift a bit to align with it to drop in.
The second idea seems a bit simpler to do. If everything is aligned on a grid then it’s a bit easier. So say the blocks are 32x32 and the ground is a grid of those boxes. I’m also assuming the boxes have their origin centered. You can calculate the closest grid position the box is on with:
Then to see if there’s a hole below it check the point (gridx, gridy+32) to see if it’s overlapping anything.
If it’s not you can then check if the x difference is close enough to make it shift into the hole. Here it would move into place if it was within 4 pixels.
Compare Gridx > box.x
Compare gridx-box.x <4
— set x to min(box.x+1, gridx)
Compare box.x-gridx <4
— set x to max(box.x-1, gridx)