How to render mesh that's inside another mesh?
You can achieve this by using render layers:



Give the cube a transparent material.
Give each object a different object index for masking with the object ID mask in the node editor (Properties Window --> Object tab --> Relations --> Pass Index).
Render, go to the node editor and set up a node tree as in the attached image or blend file.