← All notes

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

Sources

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

Permanent ID: iil:note:jhwepddn

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.},
}

Markdown

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.

All artifact files (JSON index)

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.