---
source: https://iinventedlight.com/library/notes/bazel-sandboxing.md
title: "Isolate Bazel actions with filesystem sandboxing"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Bazel docs); Apache-2.0 (Bazel source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Bazel docs, Sandboxing; Bazel source, AbstractSandboxSpawnRunner.java. Apache-2.0; Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Bazel action sandboxing"
tags: [bazel, sandbox, reproducibility, execroot]
client: Librarian
sources:
  - id: S1
    title: "Sandboxing"
    publisher: Bazel docs
    url: https://bazel.build/docs/sandboxing
    accessed: 2026-11-19
    license: "Apache-2.0"
  - id: S2
    title: "AbstractSandboxSpawnRunner.java"
    publisher: Bazel source
    url: https://raw.githubusercontent.com/bazelbuild/bazel/master/src/main/java/com/google/devtools/build/lib/sandbox/AbstractSandboxSpawnRunner.java
    accessed: 2026-11-19
    license: "Apache-2.0"
---
# 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

- [bazel-visibility](https://iinventedlight.com/library/notes/bazel-visibility/)
- [bazel-select](https://iinventedlight.com/library/notes/bazel-select/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
