Skip to content

Sandboxes ​

Permissions decide whether a call runs. But a yes can be wrong. You may allow a command without reading it to the end, or a command may do more than its name says. So what stops a command you allowed from reading your keys, or sending your code somewhere?

The idea ​

In agents generally

A permission is one guard: it decides whether a call runs. A sandbox is a second one: it decides what a running call may touch. The operating system enforces it, so it holds even when the command, or the model that wrote it, tries to get around it.

A sandbox usually limits four things:

  1. Writes. The project folder and the temp folders, and nothing else on the disk.
  2. Reads of secrets. SSH keys, cloud credentials, and the agent's own files stay closed.
  3. The network. Off by default, so a command cannot send data out or fetch a script to run.
  4. The environment. Variables that hold API keys and tokens are removed before the command starts.

The two guards cover each other. A permission can't foresee everything a command does. A sandbox doesn't know which commands you meant to allow. Together, a wrong yes costs much less.

Two guards: a permission decides whether a command runs, and a sandbox decides what a running command may touch. rm -rf ~ is stopped at the permission, because you said no. cat ~/.ssh/id_ed25519 was allowed by mistake, and the sandbox stops it. pytest -q passes both and reaches the project

How agents usually do it ​

ApproachHow it worksGood atCosts
No sandboxApprovals onlyNothing to set upOne wrong yes can do anything your user can
Checks in the toolThe tool itself refuses paths outside the projectSimple, for tools that do one thingUseless for a shell, which can do anything
An OS sandboxThe kernel limits the process: Seatbelt (sandbox-exec) on macOS, Landlock or bubblewrap on LinuxFast, and the command uses your own toolsEach OS has its own, and the rules take care to write
A containerEach command runs in Docker or a similar boxStrong walls, the same on every machineNeeds Docker, starts slowly, and sees a different toolchain than yours
A remote machineThe agent works on a VM in the cloudNothing on your machine is at riskIt is not your machine: your files, tools, and keys are elsewhere

Every version has to answer the same questions:

  • How much to close. Deny every read outside the project, and compilers and shells break, because they read from all over the home folder. Deny only the folders that hold secrets, and some files can still be read.
  • What to do without a sandbox. Run the command anyway and ask every time, or refuse to run it.
  • Who may widen it. A project file that opens the network would undo the point.

How golem does it ​

In golem

golem has two kinds of wall, besides the permission rules:

  • The shell sandbox. shell, git_status, git_diff, and git_log run under sandbox-exec, with a profile golem writes for each command. Where no sandbox can be applied, they don't run at all.
  • The file tools' folder check. read_file, write_file, and the other file tools run in the daemon, not in the sandbox. Each one resolves its path first, and refuses anything outside the session's project folder.

golem's shell sandbox in one real run, with every command allowed by a rule. touch notes.txt writes in the project folder and exits 0. touch in the home folder and ls ~/.ssh fail with Operation not permitted, curl cannot connect because the network is off, and printenv prints nothing because credential variables are removed

One shell command, in the order it runs:

  1. It is allowed, by a rule, a session allowance, or your yes (Permissions).
  2. golem writes the profile. Writes are allowed only to the project folder, the temp folders, the usual caches, and any folder in [shell] writable. Reads of the folders that hold credentials are denied. The network is off unless [shell] network = true.
  3. golem cleans the environment. Variables whose names look like credentials are removed.
  4. The command runs as $SHELL -lc <command> in the project folder, under sandbox-exec, in its own process group.
  5. A blocked action fails inside the command. macOS answers Operation not permitted, the command prints it, and it exits with an error. The model reads that as the result, and the run goes on.
  6. golem says it was the sandbox. When the output shows a refusal the profile explains, golem adds one line before the exit code: what it blocked, why, and the setting or tool that allows it. The summary becomes exit 1, blocked by the sandbox. So the model can tell you what to do, instead of telling you to check your permissions.
  7. golem hints at the network. A command can fail quietly in a pipe, such as curl -s URL | head, and end with [exit code 0]. So when [shell] network is off and the command names a network client as a whole word (curl, wget, git clone, pip install, and the others in NETWORK_CLIENTS), golem adds [the sandbox has no network: use web_fetch to read a page, or shell_unsandboxed for a command that needs the network] after the exit code. It does so whatever the exit code is. shell_unsandboxed never gets it.

Here is a real run, recorded against a throwaway home with qwen3-coder:30b on a local Ollama. A rule in config.toml allowed every shell call, so the sandbox was the only guard. The daemon was started with DEMO_API_KEY=not-a-real-key in its environment, and the home folder is shown as ~.

seqCommandtool.completed
12touch notes.txtexit 0
15touch ~/golem-sandbox-probeexit 1: Operation not permitted
18ls ~/.sshexit 1: Operation not permitted
21curl -sS -m 5 https://example.com -o /dev/nullexit 7: Couldn't connect to server
23printenv DEMO_API_KEYexit 1, and nothing printed

One write in the project, and four things the sandbox kept out: a write to the home folder, a read of ~/.ssh, the network, and a key in the environment. Afterwards, ~/golem-sandbox-probe did not exist.

This run was recorded before step 6. Now the three refused commands also end with golem's line, for example:

text
ls: /Users/you/.ssh: Operation not permitted
[golem's sandbox blocked /Users/you/.ssh: ~/.ssh holds credentials, so a sandboxed command may not read it. A command that needs it, such as gh or git push, can run with shell_unsandboxed, which the user approves first.]
[exit code 1]

Where it lives in the code:

  • packages/daemon/golem/tools/sandbox.py: profile, environment, available, run, git_dirs, and the folder lists SECRET_DIRS, SKILL_DIRS, and CACHE_DIRS.
  • packages/daemon/golem/tools/shell.py: shell and the git tools, which run through it.
  • packages/daemon/golem/tools/paths.py: inside, writable, and Readable, the file tools' folder check.

Why this way ​

sandbox-exec, or not at all (ADR-014). It ships with every macOS. A container or a VM would need software you may not have, start slowly, and see a different toolchain than yours. Apple marks sandbox-exec deprecated, so if it goes, the shell stops until another sandbox replaces it. It never falls back to a command without one: one wrong approval would be unrecoverable.

Deny the secret folders, not every read. Compilers, package managers, and your shell's startup files read from all over the home folder. Denying the folders that hold credentials keeps most of the value, with little breakage. The cost: a command you allowed can still read and print other files in your home folder.

The file tools check their own paths. They do one thing, to one path that has already been resolved, so the path check is the guard, and they need no sandbox.

A skill's folder is readable, never writable (ADR-030). A skill you ran may need its references/ and scripts/. So the read tools may read its folder, and the sandbox lets commands read ~/.golem/skills, but nothing writes there.

Only you widen it. [shell] is read only from your own config.toml. A project file cannot turn on the network or add a writable folder.

Try it ​

  1. Open the chat with golem tui in a project folder.

  2. Ask: Run ls ~/.ssh in the shell. Allow it. The result is Operation not permitted, and golem's line says ~/.ssh holds credentials.

  3. Ask: Run curl -sI https://example.com in the shell. Allow it. It can't connect, because the network is off.

  4. To let commands use the network, add this to ~/.golem/config.toml, and restart the daemon with golem daemon restart:

    toml
    [shell]
    network = true

The details ​

For contributors: the reference for the shell sandbox, the git tools, and the file tools' folders.

The shell sandbox ​

shell runs the user's login shell ($SHELL -lc) in the session folder, under sandbox-exec (ADR-014):

  • The sandbox allows writes only to the folder, the temp folders, the usual tool caches, and [shell] writable. When the folder is in a git checkout whose git folders are outside it, it may write those too, so git fetch and git commit work. In a git worktree they are its own folder, from the gitdir: line of its .git file, and the folder it shares with the main checkout, from commondir. The rest of the main checkout stays closed. golem reads the two files itself and does not run git (sandbox.git_dirs). The shared folder holds the main checkout's hooks and config, so a command could change them. A command in a plain clone could always do that, since its .git is inside the session folder. It denies the network unless [shell] network = true, except local Unix sockets. It denies reads of folders that hold credentials, ~/.ssh and ~/.golem among them, but allows reads of ~/.golem/skills, so a skill can run its scripts (ADR-030). Variables that look like credentials (*_API_KEY, *_TOKEN, *_SECRET, *PASSWORD*) are removed from the environment.
  • Policy. shell is not read-only, so by default every command asks. A rule's match is checked against the command, so match = "git status|pnpm test*" allows those and nothing else. Allowing a command for the session allows that exact command, not every command.
  • Refusals (refusals). After a sandboxed command, golem looks at its output. An Operation not permitted line whose path is in a credentials folder, or outside the writable folders, gets a line that names the folder and the fix: shell_unsandboxed, or [shell] writable. A connection error while [shell] network is off gets one that names network = true. A path the profile allows is never blamed on it, and the line is added once per kind. It reads the output, so a command that only prints such an error gets the line too.
  • Where there is no sandbox, for example inside another sandbox or off macOS, shell and the git helpers refuse to run and say why.
  • Outside the sandbox. shell_unsandboxed runs the same way without sandbox-exec, and keeps the variables that hold credentials, so gh and git push work (ADR-038). It needs no sandbox, so it runs where shell cannot. It is a tool of its own, so a rule or a session allowance for shell never lets a command out. An allow rule covers it only when it names it (NAMED_ONLY in golem/permissions/engine.py), so tool = "*" does not.

The profile, in full (profile in golem/tools/sandbox.py). It allows everything, then:

AllowedDenied
WritesThe session folder, /private/tmp, /private/var/folders, ~/.cache, ~/Library/Caches, ~/.npm, ~/Library/pnpm, ~/.cargo/registry, [shell] writable, the checkout's git folders when they are outside the session folder, and a few devices such as /dev/nullEverything else
ReadsEverything else, and ~/.golem/skills~/.ssh, ~/.gnupg, ~/.aws, ~/.azure, ~/.kube, ~/.docker, ~/.netrc, ~/.config/gh, ~/.config/gcloud, ~/.golem, ~/Library/Keychains
NetworkLocal Unix sockets, or all of it with [shell] network = trueEverything else

Paths are resolved first, because the profile matches real paths (/tmp is /private/tmp).

The environment (environment). A variable whose name contains _API_KEY, _TOKEN, _SECRET, PASSWORD, or _PASSWD, in any case, is removed. PATH gains /opt/homebrew/bin, /usr/local/bin, ~/.local/bin, and ~/.cargo/bin when they are missing. TERM=dumb, NO_COLOR=1, the pagers set to cat, and GIT_TERMINAL_PROMPT=0 keep the output plain and stop prompts.

Availability is probed once per process, by applying an empty profile. It fails off macOS, and inside another sandbox. That is also why the sandbox tests skip when golem's own tests run under golem's shell.

Its output, and how a command is stopped, are in Tools.

The git tools ​

git_status, git_diff, and git_log run git directly in the same sandbox, without the network. They switch off the repository settings that run code: core.fsmonitor, hooks, external diff drivers, and text conversion. They are read-only, so the default policy allows them.

The file tools' folders ​

The file tools run in the daemon, not under sandbox-exec, so golem/tools/paths.py is their wall:

  • Inside the folder. inside resolves a path against the session folder with symlinks followed. A path that lands outside, through .. or a symlink, is refused.
  • Never the rules or the history. writable also refuses the folder itself, and anything under a .golem/ or .git/ folder at any depth, matched without case.
  • No folder, no file tools. A session without a project folder gets the tools, and each call says this session has no project folder, so file tools are off.
  • Skill folders, for reading. The read tools also accept an absolute path inside the folder of a skill the session ran, or one it has pinned. A path there that resolves into a folder the sandbox keeps from commands is refused, so a skill folder that is a link to ~/.ssh reads nothing.

Who may read and write where (ADR-030):

PathRead toolsShell (sandbox)Write tools
The session folderyesread and writeyes
The folder of a skill the session ranyes, by absolute pathreadno
~/.golem/skills/… before the skill runsnoreadno
~/.golem/golem.db, logs, confignonono

web_fetch has its own wall: it refuses private and local addresses (Tools).

Files ​

FileWhat it does
packages/daemon/golem/tools/sandbox.pyThe profile, the environment, the availability probe, and running a command
packages/daemon/golem/tools/shell.pyshell, git_status, git_diff, and git_log
packages/daemon/golem/tools/paths.pyinside, writable, Readable, and PROTECTED_DIRS

Read more ​