I run this command at the command line:

 $ sudo chroot . node test/simple.js

And I get this error:

chroot: failed to run command ‘node’: No such file or directory

makes sense, since the node executable is located in a file below the PWD. So what is a good way to get the node executable within the PWD, should I symlink it?

Ultimately however, I am most interested in allowing all executables to run in the chroot jail, but only allow reading and writing to files within the chroot jail, AKA:


so say I do:

cd jail/foo
sudo chroot . ../randos/node ../randos/a.js

that should fail because I shouldn't be able to read randos/a.js. But if I do this:

cd jail/foo
sudo chroot . ../randos/node foo.js

then it should work, even if the node executable file is not a file within the jail.

Also, as an aside, if anyone knows how to get chroot to run without sudo for a certain directory, that'd be good.

closed as unclear what you're asking by Ipor Sircer, Isaac, filbranden, G-Man, Thomas Nov 25 '18 at 11:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


I would use the symlink option.

Also to answer your aside, I would edit your sudoers file.

Add a line that looks like:

SOMEUSER  ALL=/usr/sbin/chroot /DIR/TO/JAIL
  • thanks for the info, upvoted. yeah but in this for a library, I need all executables outside the jail to be available, and I'd rather not permanently change the sudoers file. – Alexander Mills Nov 24 '18 at 20:09
  • Yea, that makes things more interesting... @AlexanderMills – Michael Prokopec Nov 24 '18 at 20:14
  • yeah I don't think chroot works the way I want, might have to find a different solution, perhaps a Docker container is the only way idk – Alexander Mills Nov 24 '18 at 20:24
  • Here is the ultimate goal, btw: github.com/nodejs/node/issues/24633 – Alexander Mills Nov 24 '18 at 20:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.