will help you If you use chroot(), you have to consider the consequences of what you do. One of the major consequences is that many (most, all) of the commands normally available are not available unless you make them available in the chroot()'d environment. Doing that job properly is non-trivial. You may need parts of /dev, /bin, /etc, /usr, /lib (and probably others too) installed appropriately under the new root directory. Symlinks back to 'outside the chroot() environment' won't work, in general. You have to make copies of what's important. One side effect of all this: /tmp is very rarely an appropriate place to create a fully operational chroot() environment. You might get away with a limited access sub-directory under /tmp, but putting a user in /tmp doesn't isolate them from other users, or other users from them, very well.
seems to work fine Chroot should handle this just fine. Just make sure that your perl script can find a Perl interpreter from the chroot context, that the Perl executable can find the shared libraries it needs, and that your variables, if they contain paths, have paths relative to the new root, not the old. You may want to compile a statically-linked perl executable, if that's easier for you than making copies of the required shared libraries in the chroot.
Bash: executing commands from within a chroot and switch user
around this issue Either the binaries you copy in to your chroot environment must be statically linked, or you need to copy in the necessary shared libraries as well (/lib / /usr/lib). Non-root processes can execute in a chroot environment just as root processes can, but only root processes can call chroot() so you will need to have a root process set up the chroot environment and then switch to the unprivileged user id.
should help you out When you run chroot without telling it what to do, it will try to start chrooted interactive shell session. So your script would "pause" at that point and when you are done with that interactive shell session, it continues out of chroot again. One of the quick and dirt options would be to abuse here-document, like this:
chroot /home/mayank/chroot/codebase /bin/bash <<"EOT"