OSL script node : detect if two object collides and output a bool
I've been working on something that goes somewhere towards answering your problem.. don't take it too seriously, I'm only getting used to some of the quirks of OSL in Blender/Cycles: some of these conditionals may look unnecessary, but for example, if I don't use the 'hit' local variable, it won't work, even though I don't need to.

#include "stdosl.h"

shader Dipper(
    string Container = "",
    output int IsInside = 0
)

{      
    if  ( raytype("refraction") != 1 ) IsInside = 0;
    else{

        int ray_depth;
        getattribute("path:ray_depth", ray_depth);

        if  ( ray_depth % 2  != 0){

            string source_name;
            int hit;
            hit = trace (P,I);
            getmessage ("trace", "geom:name", source_name);

            if (hit==1){
                if (source_name == Container ){ 
                    IsInside =1;
                }
            }
        }
    }   
}




You enter the name of your container object in the 'Container' input,(unquoted).



I'm also pretty sure you could make the logic of this shader fail, without too much effort.