Documentation
¶
Overview ¶
Package sandbox confines a dispatched agent's filesystem access to what its task needs (dispatch.sandbox, #481): read-write its worktree, the project's database directory, the git directory its commits land in, /tmp and its own CLI's config; read-only the system and the toolchains on PATH; nothing else in $HOME — not ~/.ssh, not another project, not another task's worktree.
The mechanism is Landlock, Linux only. A Landlock ruleset binds the process that applies it and every child it forks, and cannot be lifted, so it is applied in a launcher rather than in orch: the engine spawns `orch sandbox-exec --rw … --ro … -- <cli> <args>`, which restricts itself and then execs the CLI in its place (Wrap, Exec). The process group, the log file descriptors and the timeout the engine set up all carry over the exec unchanged.
Policy building (For) is pure, so the path list is pinned by unit tests; applying it is in sandbox_linux.go.
Index ¶
Constants ¶
const Command = "sandbox-exec"
Command is the hidden subcommand the launcher runs as.
const MinABI = 2
MinABI is the oldest Landlock ABI the sandbox runs on. ABI 1 (Linux 5.13 to 5.18) cannot grant renaming a file across directories, which git does on every commit (an object moves from a temporary name into objects/xx/); go-landlock's best-effort mode then turns the whole ruleset into a no-op rather than break that. A sandbox that silently confines nothing is worse than none, so ABI 1 is refused like a kernel without Landlock.
Variables ¶
This section is empty.
Functions ¶
func ABI ¶
ABI is the kernel's Landlock ABI version, or an error saying why there is none: an old kernel, or Landlock left out of the boot's lsm= list.
func Available ¶
func Available() error
Available is nil when the sandbox can confine an agent here.
func Exec ¶
Exec confines this process to p and replaces it with argv. It returns only on failure, and then nothing was exec'd: an agent never runs unconfined because its sandbox could not be applied.
The ruleset is go-landlock's V8 in best-effort mode, so a kernel with an older ABI (2 and up, Available checks) enforces the subset it knows instead of failing. V8, not newer: V9 starts handling connect(2) on UNIX sockets, which would cut agents off docker.sock.
Types ¶
type Options ¶
type Options struct {
// Backend picks which CLI's config directories are writable.
Backend model.Backend
// Workdir is the task's worktree (the project root without worktree mode).
Workdir string
// Writable are other directories the agent must write: the database
// directory `orch done` writes, the git common dir a worktree commits into.
Writable []string
// Readable are other paths it must read: the project root (config.yaml,
// .claude/settings.json), the prompt's directory, orch's own binary.
Readable []string
// Home is $HOME; PathEnv is $PATH; TempDir is os.TempDir().
Home, PathEnv, TempDir string
}
Options are the facts For needs about one dispatch.
type Policy ¶
Policy is what a sandboxed agent may touch. A path covers everything beneath it; a file path covers that file. Paths that do not exist when the launcher starts are skipped.
func For ¶
For builds the policy of one dispatch.
Every directory on PATH is readable, and so is the parent of one named bin (~/.nvm/versions/node/vX/bin's node_modules live beside it). A path that is $HOME itself or above it is dropped whatever asked for it — a PATH entry like ~/bin must not open the whole home directory — and so is anything relative.