Chroot Sandbox
This article discusses a way of setting up a sandbox in Linux that prevents applications run under the sandbox from making critical changes to real files. This can be useful to test applications or to test out some changes that you don't want to commit to the main files.
Directory Layout
The root of our sandbox will contain three directories:
- SANDBOX/mount
- This is the mount point for the sandbox
- SANDBOX/ro
- This is used to override files from the root.
- SANDBOX/rw
- This is where any changes will be written.
Creating the Sandbox
I used unionfs-fuse to create the sandbox with everything already in root, then mounted some additionional filesystems on top of that.
Getting in the Sandbox
Now it is time to chroot into the sandbox.
Once in the sandbox, applications will only write to $SANDBOX/rw. It is possible to install applications under the sandbox, make changes for testing, and more without affecting anything outside. Because of the extra mount points, it is also possible to play games and videos.
Changes outside of the sandbox may inadvertently affect changes made in the sandbox. Files from the root can be copied to the $SANDBOX/ro directory.