Isolate Bazel actions with filesystem sandboxing
Answer: Sandboxing is a strategy that isolates processes from each other, or from system resources. In Bazel, the goal is restricting file system access. The file system sandbox runs each process inside a working directory that contains only known inputs.
execroot
For each action, Bazel constructs an execroot/ directory, used as the action's work directory at execution time. That execroot/ contains the action's input files, and any generated outputs. Bazel constrains the action with containers on Linux and with sandbox-exec on macOS, keeping it inside execroot/.
Sandboxing does not hide the host environment. Processes may still access files on the file system. On platforms that support user namespaces, though, a process can't modify files outside its working directory.
| execroot | sandbox | |---|---| | work directory | execroot/ | | Linux | containers | | macOS | sandbox-exec | | user namespaces | working directory |
Incremental builds
Without action sandboxing, Bazel cannot tell whether a tool uses undeclared input files. If one of those undeclared input files changes, Bazel may still treat the build as up-to-date and will not rebuild the action, which can yield an incorrect incremental build.
The class AbstractSandboxSpawnRunner is an abstract common ancestor of the sandbox spawn runners, and it implements the common parts. A hook can retrieve the list of directories that the spawn will assume to be writable.
See also
Claims
- id: C1 claim: For Bazel, sandboxing means restricting file system access for action processes. source: S1 evidence: "For Bazel, this means restricting file system access."
- id: C2 claim: Each action gets an execroot/ work directory that holds its inputs and outputs. source: S1 evidence: "Bazel constructs an
execroot/directory for each action"
- id: C3 claim: AbstractSandboxSpawnRunner is the shared ancestor of sandbox spawn runners. source: S2 evidence: "Abstract common ancestor for sandbox spawn runners implementing the common parts."
Sources
- [S1] Sandboxing. Bazel docs. https://bazel.build/docs/sandboxing . License: Apache-2.0. Accessed 2026-11-19.
- [S2] AbstractSandboxSpawnRunner.java. Bazel source. https://raw.githubusercontent.com/bazelbuild/bazel/master/src/main/java/com/google/devtools/build/lib/sandbox/AbstractSandboxSpawnRunner.java . License: Apache-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Bazel docs, Sandboxing; Bazel source, AbstractSandboxSpawnRunner.java. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Bazel docs, Sandboxing; Bazel source, AbstractSandboxSpawnRunner.java. Apache-2.0; Apache-2.0.
Cite this
iinventedlight. 2026. "Isolate Bazel actions with filesystem sandboxing." iinventedlight Library, iil:note:jhwepddn, version of 2026-11-19. https://iinventedlight.com/library/notes/bazel-sandboxing/. License: CC-BY-4.0.
@misc{iil_note_jhwepddn,
author = {{iinventedlight}},
title = {{Isolate Bazel actions with filesystem sandboxing}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/bazel-sandboxing/},
note = {Permanent ID iil:note:jhwepddn. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- bazel-sandboxing.table.json (table; CC-BY-4.0)
- bazel-sandboxing.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/bazel-sandboxing.md.