Masking objects that enter another objects region


Ok so I have a black cube that has its normals flipped and backface culling enabled. Is there any way to have the red cube masked black where it enters the black cube while having the blue cube remain seen?
Like so:

Preferably the shader node setups would be on the black and blue cubes so that any other mesh intersecting the black cube will turn black automatically.

An alternative way to achieve the effect I want would be to have the black cube have unflipped normals while the blue cube inside is projected on top of it.

I don’t know if this is remotely possible with Blenders shader node system but I might as well ask around to see if anyone would know where to start. Thanks in advance!