OS sandboxes and openmoat run
The hook decides each call, but an allowed npm test can run any code. So OpenMoat also writes your policy into an OS sandbox, which confines every process the agent's commands start: the agent's own sandbox (Claude Code, Codex, Cursor), or openmoat run for any agent.
When you need it
Try it
openmoat run --write ~/.claude --write ~/.claude.json -- claude# the project's test script, started as npm test inside the run cat "$HOME/.ssh/id_rsa" macOS, openmoat run (Seatbelt) EPERM Linux, openmoat run --no-isolate (Landlock) EACCES Linux, openmoat run --isolate (bubblewrap) ENOENT curl -fsS -o /dev/null -m 30 http://evil.example/ every tier proxy 403
What the operating system answered, from the table below that CI checks on every pull request (EVIDENCE.md in the openmoat repository). ENOENT: the path does not exist inside the sandbox.
Change it
openmoat sandbox show prints what your policy compiles to; run openmoat sandbox sync after openmoat edit. sandbox.read_roots lists what sandboxed commands may read beyond the rules.
What it does not stop
Claude Code's sandbox covers Bash, PowerShell and Monitor: file tools, WebFetch and MCP servers are checked by the hook only. openmoat run refuses on macOS 12 and earlier and on Windows. All its limits
Protects against code inside an allowed command (a test script, a build step, an install script) reading your keys, writing outside the project or connecting to hosts the policy does not allow.
What it does
Section titled “What it does”The hook decides each call, but an allowed npm test can run any code. So OpenMoat also writes the policy into an OS sandbox, which confines every process the agent’s commands start: no secrets, no reads outside the project and sandbox.read_roots, no writes outside the project, and network only to the hosts the policy allows.
| Tier | Set up by | What it confines | Platforms |
|---|---|---|---|
| The agent’s own sandbox (Standard) | openmoat init, kept in step by openmoat sandbox sync |
The commands the agent runs: Claude Code’s Bash, PowerShell and Monitor; every Codex command; Cursor’s terminal commands |
Claude Code: macOS, Linux, WSL2. Codex: every OS. Cursor: macOS, Linux |
openmoat run (Lightweight) |
openmoat run -- <agent> on macOS; on Linux where bubblewrap cannot start, or with --no-isolate |
The whole agent and everything it starts, in one sandbox, with network only through OpenMoat’s proxy | Seatbelt on macOS 13 or later; Landlock and seccomp on Linux 6.7 or later |
openmoat run (Isolated) |
openmoat run -- <agent> on Linux where bubblewrap works (the default from 0.20.0); --isolate refuses without it |
As above; the agent sees only the project, the read roots, its executable, the --write paths and an empty temp directory |
Linux, with bubblewrap |
What openmoat init writes:
- Claude Code: the
sandboxblock andpermissions.blockReadsOutsideWorkingDirectoriesin itssettings.json; - Codex: a
[permissions.moat]profile,default_permissions = "moat"andfeatures.network_proxy = truein itsconfig.toml; - Cursor:
sandbox.jsonnext to itshooks.json.
Each file is backed up to <file>.moat-sandbox-backup first, and openmoat uninstall takes the settings out again.
From 0.16.0 every sandbox also denies the agents’ login and key files to the commands an agent runs, so a test or package script cannot read a token; openmoat run keeps the login of the agent it starts readable (Agent logins and keys).
OpenClaw, GitHub Copilot CLI, pi, Gemini CLI, OpenCode, Hermes Agent, the Cline CLI and goose have no sandbox OpenMoat can configure: use openmoat run for them. Without it, running a script the session wrote needs review first (Code the agent wrote).
Since 0.26.0:
- A protection score.
openmoat doctorandopenmoat run --print-boundaryshow one 0 to 100 score for how much of the OS boundary is in force, naming each missing part;sandbox.strict: truerefuses any run below 100. On Linux 7.2 the run also refuses UDP through Landlock (Protection score and strict mode). - Qwen Code and Crush get an
openmoat runcommand, andopenmoat statusnames each hook-only agent that has one, with the command as the fix. - Windows.
openmoat runstarts a preview tier on native Windows that holds writes and the process tree, not reads or the network (openmoat run on Windows).
Example
Section titled “Example”The project’s test script, started as npm test (which the hook allows), in a throwaway home with fake secrets. Each cell is what the operating system did; CI asserts every cell on every pull request (EVIDENCE.md):
| Payload | openmoat run, macOS (Seatbelt) |
openmoat run --no-isolate, Linux (Landlock + seccomp, network namespace) |
openmoat run --no-isolate, Linux without bubblewrap |
openmoat run --isolate, Linux (bubblewrap; the default where it works) |
Claude Code sandbox, macOS | Claude Code sandbox, Linux | Codex moat profile, macOS |
Codex moat profile, Linux |
|---|---|---|---|---|---|---|---|---|
cat "$HOME/.ssh/id_rsa" |
EPERM | EACCES | EACCES | ENOENT | EPERM | ENOENT | EPERM | EACCES |
cat .env |
EPERM | EACCES | EACCES | EACCES | EPERM | EACCES | EPERM | EACCES |
echo '# PLANTED' > .git/hooks/pre-commit |
EPERM | EROFS | EACCES | EROFS | EPERM | EROFS | EPERM | EROFS |
echo x > "$HOME/outside.txt" |
EPERM | EACCES | EACCES | EACCES | EPERM | contained | EPERM | contained |
echo "# widened" >> "$HOME/.moat/policy.yaml" |
EPERM | EACCES | EACCES | ENOENT | EPERM | ENOENT | EPERM | EACCES |
ln -s "$HOME/.ssh" keys && cat keys/id_rsa |
EPERM | EACCES | EACCES | ENOENT | EPERM | ENOENT | EPERM | EACCES |
curl -fsS -o /dev/null -m 30 http://evil.example/ |
proxy 403 | proxy 403 | proxy 403 | proxy 403 | proxy 403 | proxy 403 | proxy 403 | proxy 403 |
ENOENT: the path does not exist inside the sandbox. contained: the write completed in an in-memory directory and nothing reached the disk. proxy 403: the layer’s proxy refused the request. The one known gap (#174): on Linux without bubblewrap, a command cannot create a new file directly at the project’s top, since the project is granted entry by entry there (Project files on Linux).
Run a whole agent
Section titled “Run a whole agent”openmoat run --write ~/.claude --write ~/.claude.json -- claudeopenmoat run --isolate --write ~/.claude --write ~/.claude.json -- claude # Linux: refuse without bubblewrapThe two --write paths are Claude Code’s own state, which it must write to run. Start openmoat run in a project, never in your home directory.
- Network then goes only through the run’s proxy, and the agent’s hooks still decide each call.
- On Linux it starts the Isolated tier where bubblewrap works (Linux tiers and Landlock).
- It also takes a snapshot of the project before and after, for
openmoat restore(Undo an agent’s changes), and records the sandbox it really started with (The boundary record).
Everything it does, and the Cursor CLI setup: Run a whole agent with openmoat run.
Commands
Section titled “Commands”| Command | What it does | Example |
|---|---|---|
openmoat sandbox show |
The sandbox settings the policy compiles to, with every place a sandbox is stricter or wider; writes nothing | openmoat sandbox show |
openmoat sandbox sync |
Write them for the agents whose hook is installed, and re-pin. Terminal only | openmoat sandbox sync |
openmoat status |
Each agent’s level: hook + OS sandbox, hook only or not protected |
openmoat status |
openmoat doctor --verbose |
Every place each agent’s sandbox is stricter or wider than the policy | openmoat doctor --verbose |
openmoat policy compile |
What the OS layers enforce for the policy, and what they cannot | openmoat policy compile --format json |
openmoat run [--write <path>]… -- <agent> |
Run an agent in a sandbox made from the policy | openmoat run -- claude --dangerously-skip-permissions |
openmoat run --isolate · --no-isolate |
Linux: the Isolated tier or refuse; the Lightweight tier on purpose (recorded) | openmoat run --isolate --write ~/.claude -- claude |
openmoat run --print-boundary [--format json] |
Print the boundary a run would start with and start nothing (from 0.21.0) | openmoat run --print-boundary -- claude |
openmoat run --netns=require |
Refuse to start on Linux where the agent cannot get a network namespace, instead of restricting its network by port only | openmoat run --netns=require -- claude |
openmoat allow and openmoat secret add update the agents’ sandboxes for you. After openmoat edit or openmoat policy upgrade, run openmoat sandbox sync, then start a new agent session.
Settings
Section titled “Settings”sandbox: read_roots: ["/usr", "~/.cargo"] # what sandboxed commands may read beyond the rules proxy_port: 18080 # optional: send sandboxed traffic through openmoat proxy package_min_release_age_days: 7 # openmoat run: npm and uv skip newer versions; 0 is off project_top: protected # Linux without bubblewrap: `writable` opens the project's top, on recordread_roots lists directories or files, never globs; deny rules still win inside them (~/.cargo/credentials.toml stays denied). A policy without a sandbox: section gets the default list (system directories, temp directories and toolchain homes). proxy_port: see Egress proxy. project_top (from 0.21.0, your own policy only): see Project files on Linux.
Limits
Section titled “Limits”- Claude Code’s sandbox covers
Bash,PowerShellandMonitor. File tools,WebFetchand MCP servers are checked by the hook only. - Cursor runs some commands outside its sandbox: when its Auto-review approves them, in Run Everything mode, and in the Cursor CLI without
--sandbox enabled. Inside the workspace its sandbox cannot deny.envor.git. - On Linux without bubblewrap,
openmoat runcannot create anything directly at the project’s top. From 0.21.0 it grants the project entry by entry there, so.env,.gitand.moatat the top stay covered; a.envin a subfolder or a nested.gitstays open, andsandbox.project_top: writableopens the top again, on record (Project files on Linux). Without bubblewrap, its network is restricted by port only and a--writepath outside the project is refused. - Under
openmoat run, the project’s.gitis read-only (macOS, and every Linux tier from 0.21.0), and agent configuration folders in the project cannot be written: commit, pull and install outside the run. openmoat runrefuses on macOS 12 and earlier. On native Windows it is a preview that holds writes and the process tree only (since 0.26.0), and Claude Code and Cursor get no sandbox from OpenMoat there: use WSL2 for the full boundary (openmoat run on Windows).- Under
openmoat run, the agent and its commands share one sandbox: whatever the agent needs,npm testgets too.
The details per agent: SANDBOX.md. More in Limits.