How can I delete all meshs that exist inside of another mesh. Example inside

I have a complicated mesh that I am trying to work with, but I created a simple demo to illustrate my issue. As you can see, I have a mesh, that has three parts. An outside cube, a Sphere that exists half in/out of the cube, and a cube that exists totally inside the cube. I want to end up with one shell, where only the cube and the half sphere exists, i.e. the loose sphere, and the interior half of the large sphere are deleted. I tried various methods like trying to select non-manifold faces, loose objects, but nothing works. Any ideas?

inside_cube.blend (943.2 KB)

If you want to do it once you can use Separate by loose parts operator to have each mesh as different object then delete the small sphere manually in the Outliner:

If you want to do it programmatically you can do it with Geometry Nodes and Raycast node but it might be more complicated with overlapping meshes.

There is no non-manifold face, here. There are 3 manifold surfaces.
For same reason, there is no loose geometry. No face, edge or vertex isolated.
All components have neighbors.

You can select all.
Open Faces menu > Intersect (Boolean)
In F9 panel, set operation to Union, solver to Exact, enable Self Intersection option.

Or

You can do a Voxel Remeshing in Object or Sculpt mode.

After separate by loose parts you’ll get 3 separate objects:

I’d remove the small sphere before boolean to save on computing time. Especially if the original mesh is dense.