Selecting all objects inside a mesh
Since script is not here so one handmade tech. using Dynamic Paint from Physics Properties. Tested with official 2.82


for Torus add Dynamic Paint as Brush
Join Cubes Ctrl+J, add Dynamic Paint as Canvas &gt; Surface Type &gt; Weight and in Output click &quot;+&quot; icon if &quot;dp_weight&quot; is marked red. When you switch to Weight Paint mode you can see all Cubes placed inside Torus are red.
Apply modifier for Cubes


When you switch to Edit mode you can see weight color as well if you enable Viewport Overlays &gt; Vertex Group Weight.

To select red cubes go to Properties Editor &gt; Object Data &gt; Vertex Group &gt; Select
Because some of the cubes were selected only partialy, you can select whole these by Select Linked Ctrl+L.


Notes: If you need Cubes separated back, just press P &gt; by Loose parts.
(In experimental 2.83 I have some glitches in 3Dview editor &gt; Weight Paint mode, but weight is visible from XYZ axis.Probably some personal issue with graphics card, because on Eevee mode Blender crash totaly.)
Just for fun ...