How to pass node.js objects to child process and then access those objects

Actually i am doing sanboxing through child process. I am using vm.runincontext method to run scripts. I am passing code to child process using child.stdin.write and reciving in child using stdin.on('data' function())... now what i want is that script can access some node.js objects or user defined object through context and that context will be passed to child process dynamically and it will run sanbox in that context. currently i am creating context object in child process but i don't want that i want to pass context object to child process.

In general you can't really do this sort of thing, as basically you are trying to share data (ie memory) across processes which is a big no-no

But using nowjs can get you pretty close. Check out nowjs and hook all of your processes up to it

Consider what you're asking. You would have to serialize not only the current execution context, but all other upstream contexts, the entire global namespace, file descriptors...

In other words, this would be an insane amount of work, and you can't. :-)

What you can do is serialize data and send that back and forth over the stdout/stdin handles. That's how this problem is typically solved.

Hope that helps.