Is a chroot jail a security sandbox?
Short answer
No. chroot(2) "changes an ingredient in the pathname resolution process and does nothing else," and the man page states it is "not intended to be used for any kind of security purpose, neither to fully sandbox a process nor to restrict filesystem system calls." Open file descriptors are not closed and may reach files outside the new root, and the superuser can escape. For real isolation use Linux namespaces (and the other mechanisms containers combine) or a VM.
Many engineers learn chroot as "jailing" a process and assume it is a security boundary. The man page says otherwise, and interviewers like the question because the wrong answer sounds so reasonable.
What chroot actually does
chroot(2) changes the process's idea of the root directory, so absolute paths are resolved from a new starting point. The man page puts it plainly: the call "changes an ingredient in the pathname resolution process and does nothing else." It does not hide processes, networks, users, or other resources.
Why it is not a sandbox
The man page says chroot is "not intended to be used for any kind of security purpose, neither to fully sandbox a process nor to restrict filesystem system calls." Two concrete holes it documents: the call "does not close open file descriptors, and such file descriptors may allow access to files outside the chroot tree," and the superuser can escape a chroot jail. A process that keeps a handle to something outside, or that runs as root, is not contained.
What to use instead
Isolation needs mechanisms that give a process a private view of system resources. Linux namespaces do this per resource: mount, PID, network, user, IPC, UTS, cgroup, and time namespaces each isolate a different global resource. Container runtimes combine several such mechanisms; a VM is stronger still. chroot can remain a useful convenience (for example a build root) but never the control you rely on.
Why the distractors are tempting
"Cannot name any path outside, even as root" is the myth itself. "Drops privileges and closes descriptors" invents behaviour the man page explicitly denies. "Obsolete and does nothing" overcorrects: it works as documented, just not as a security boundary.
What interviewers want
A clear "no," the two escape routes (root, inherited descriptors), and a pointer to namespaces or VMs for real isolation.
Likely follow-ups
- How could a chrooted process running as root break out of the jail?
- Why does an open file descriptor to a directory outside the new root defeat the jail?
- Which Linux namespaces would you combine to isolate a process properly, and what does each isolate?