To test: Add cube, duplicate 6x along x with grid snap on. (Move each duplicate cube along the axis so that the two cubes' side faces 'touch'). Take this group duplicate 6x along y with grid snap on. Then take this group duplicate 6x along z with grid snap on. You should now have a nested 'cube' made up of 216 smaller cubes with no gaps.
Now delete some random inner cubes and a few of the cubes making up the 6 walls of the larger cube. Something like Minecraft. You should be able to travel through tunnel-like spaces through the large cube.
Select all remaining cubes and join them into one mesh (Object>Join).
In Edit mode, select all vertexes. Go to Mesh>Merge>By distance. Set distance to around 1.2m to select all double and remove them.
Then, still in Edit mode, on Face Select, go to Select All By Trait> Interior Faces.
And there's the problem: While Blender does select most of the included/occluded interior faces, it doesn't select all of them. And, additionally, it selects some faces that are exterior facing.
This is not what is supposed to happen. It seems quite random and unreliable and needs to be fixed.
Whatever algorithm / coding is used to execute this process is not fit for purpose and another method must be found to perform this (should be) useful function.