All benches on a host run as one Linux user. A web worker is a normal process of that user. If someone gets code to run in it, through a bug in a site or through a bad app, that code can do what the user can do. It can read ~/.ssh, read the other benches, read the admin secrets in bench.toml, and use the sudo rules that Pilot installs.
The sandbox makes that process see less. systemd starts each workload process with its own view of the machine. The process is still the same user, but its home directory is an empty folder, the other benches are not there, the system is read-only, and sudo fails. Pilot asks systemd for this with extra lines in the unit file of each workload process.
The sandbox limits the damage when a running workload is compromised. It does not separate one bench from another, and it does not make an app that you install safe. See What the sandbox does not do.
| Place | In the sandbox |
|---|---|
| Home directory | Empty, so ~/.ssh, the other dotfiles and the user bus are not there. |
Other benches and common_config.toml |
Not there. |
bench.toml, .credentials and the admin's tasks/ |
Not there. |
sites, config, logs, pids, chromium and flow-server in the bench |
There, and writable. logs is the workload's own folder, logs/workload on disk, so the workload cannot touch the log files that Pilot and systemd write. |
apps and env in the bench |
There, and read-only, because the Admin and the CLI run this code outside the sandbox. |
Pilot's own files in config/, and sites/common_site_config.json |
Read-only. |
| The rest of the system | Read-only. Host sockets in /run, such as docker.sock, are hidden. |
/tmp |
Each process has its own. |
| sudo and setuid programs | Fail. |
| Network | Works as before. |
The systemd directives behind each row are in Production.
On a sandboxed bench, Frappe's own log files, such as frappe.log, database.log and scheduler.log, are in logs/workload/ on disk. The unit output (web.log, admin.log) and the audit log stay in logs/. If logs/workload is a link, Pilot refuses to write the units and says so. A bench without the sandbox is unchanged.
The Admin log viewer lists the files in logs/ by name and the files in logs/workload/ as workload/<name>. Both show when they have the same name: CLI and Admin runs write Frappe's logs to logs/, and the sandboxed workload writes them to logs/workload/. It opens each file once, without following a link, and reads only regular files. It does not list a symlink or a named pipe, and it cannot read or download one.
nginx runs outside the sandbox as the bench user and serves sites/ from disk, so a link that a workload makes there could reach a file the workload cannot read. For that reason nginx follows no symlinks below a sandboxed bench. A bench without the sandbox keeps its links, because its workload can already read those files. See Nginx And TLS.
Pilot adds the sandbox to every workload unit that it writes for a systemd bench.
| In the sandbox | Not in the sandbox |
|---|---|
| web | The Admin and its task worker |
| socketio | The central bootstrap unit |
| Worker pools | The database units, pilot-mariadb and pilot-postgres |
| redis cache and redis queue | Pilot's host units, such as the monitor and the certificate renewal timer |
App processes, with their pre_run and post_run hooks |
Anything that you run with the pilot CLI |
| A Supervisor bench and the dev runner |
The Admin stays out because it runs the nginx and certbot commands with sudo. get-app, install-app, migrate and asset builds run from the CLI or as Admin tasks, so the app code that they run is outside the sandbox too.
A Frappe run outside the sandbox writes its log files in sites/<site>/logs/, where a workload can plant a link. On a sandboxed bench, Pilot starts every such run through pilot/managers/processes/unsandboxed_entry.py, which opens each log file below the bench one folder at a time and refuses a link at each step. The run then fails instead of writing through the link. Remove the link to run it again.
[production]
process_manager = "systemd"
sandbox = true # or false- A new systemd bench has no
sandboxsetting and runs in the sandbox. - A bench that existed before the sandbox became the default got
sandbox = falsefrom a patch, so an update does not change how it runs. Setsandbox = trueto opt in, or runpilot set-bench-config production_sandbox true.pilot restartapplies it. sandbox = truewith Supervisor is a config error.
Before Pilot writes the units, it starts a trial unit with the same directives. If the host cannot start it, a bench with no setting runs without the sandbox and Pilot logs the reason. A bench with sandbox = true fails with the systemd error and keeps its current units.
The sandbox also needs Python 3.11 or later in the bench venv. Pilot must be able to read the version from the venv. Outside the sandbox Pilot runs that Python with -P, in sites/, so a package that a workload plants in sites/ cannot replace Frappe. Python 3.10 has no -P. A bench on it, or with a venv of unknown version, is treated like a host that fails the trial. A new bench has no venv until setup builds it, so Pilot checks the version when setup writes the units again.
The trial needs unprivileged user namespaces. Ubuntu 24.04 blocks them through AppArmor (kernel.apparmor_restrict_unprivileged_userns = 1), so there the trial fails with exit code 226.
An empty home breaks things that a bench needs. So Pilot puts back, read-only, what its own workloads use: the Python that the venv links to (with the minor-version alias that uv links a venv through), Node, nvm and linked apps. The database socket stays hidden, because its unix_socket login lets the OS user in with no password; sites connect over TCP instead. An app that needs more says so in its own pyproject.toml. Pilot does not need to know the app.
# For every workload unit of the bench, while a site uses the app.
[tool.pilot.sandbox]
read_paths = ["~/.cache/models"]
write_paths = ["mail-data"]
# For this process only.
[tool.pilot.processes.stalwart]
command = ["./bin/stalwart"]
write_paths = ["/var/lib/stalwart"]A process can read a path in read_paths. It can read and write a path in write_paths. A path is a folder in the bench (mail-data), in the home directory (~/...) or on the system (/...). Pilot accepts a home or system path only below a short list of roots, and it refuses some reserved names. The rules are in App Processes.
The sandbox does not separate one bench from another. All benches run as one user, so code in one bench can read the files and environment of another bench's processes through /proc/<pid>, signal them, and reach their redis and other ports on 127.0.0.1. Put workloads that must not reach each other under separate host users. Outbound network access also stays open.
The sandbox does not protect you from an app that you install. An app chooses its own read_paths and write_paths, and the ones under [tool.pilot.sandbox] apply to every workload unit of the bench. Pilot checks that a path is below an allowed root, but it cannot know what the path is for. So an app can ask for the data of another program that the host user can read, such as ~/.local/share/containers. App code also runs without the sandbox during get-app, install-app, migrate and asset builds. Install only apps that you trust.
A link that was planted in the real logs/ before the bench got the sandbox stays until someone removes it.
File permissions still apply in the sandbox, so a process never gets more than the host user has.
The Trust Model lists what follows from one shared host user.