You could spawn the process as an argument for chroot
, which will change the root directory for your process:
spawn('chroot', ['/tmp/running/username', 'yourprocess', 'arg1', ...]);
An alternative would be to use the chroot
function from the node-posix module (but to prevent the Node process from which you spawn your external program from being chrooted as well, you may need to fork first and call chroot from the child process).