Dynamic limit distance?

Is there a way to make a cube limit its distance from an arbitrary mesh, kind of like the opposite of shrink wrap?

Such that when the target mesh gets to close to the cube, it won’t let the cube pass through its surface, but otherwise the cube can move free around it and perfectly follow its surface if it is in contact.