Code the agent wrote
Where no OS sandbox from OpenMoat holds the command, running a script the same session wrote needs review first: the script can do what the hook cannot see in the command line.
When you need it
On agents without an OS sandbox from OpenMoat, and on Claude Code and Cursor on native Windows (Supported features).
Try it
python3 x.pymoat: review [session-written-code] — runs code this session wrote, with no OS sandbox below the hook: /p/x.py
What the agent is told when it runs /p/x.py, a file it wrote in the same session.
Change it
Read the script, then run openmoat allow --last: it covers that command until the agent writes the file again. --always is refused here, since a rule cannot vouch for code the agent may rewrite.
What it does not stop
Test runners, build tools and package scripts (pytest, npm test, cargo test, make, go run .) running files the session wrote do not need review. All its limits
Protects against an agent writing a script and running it, so that the script does what the hook cannot see: build the path of ~/.ssh/id_rsa from pieces, read the key and send it to an allowed host. Nothing on the command line names the key, so no deny rule can match.
What it does
Section titled “What it does”When the agent runs a file the same agent session wrote, and no OS sandbox from OpenMoat holds the command, the call needs review with rule session-written-code. The reason names the file:
moat: review [session-written-code] — runs code this session wrote, with no OS sandbox below the hook: /p/x.py| Where | What happens |
|---|---|
| OpenClaw, GitHub Copilot CLI, pi, Gemini CLI, OpenCode, Hermes Agent, the Cline CLI, goose | Needs review. OpenCode 1, the Cline CLI and goose cannot prompt, so there it is denied (blocked, in goose) with the openmoat allow --last hint |
| Claude Code and Cursor on native Windows, or with their sandbox not in place | Needs review |
| Claude Code, Codex and Cursor with their sandbox in place on macOS and Linux | Unchanged: the OS sandbox stops the script’s read of the key |
Any agent inside openmoat run |
Unchanged: the run’s sandbox holds the whole agent |
“Sandbox in place” is what openmoat status reports as hook + OS sandbox.
What counts as running the file:
- an interpreter given the file:
python3 x.py,python3 -u x.py,python -m tool,node x.js,node -r ./x.js,deno run,bun,ruby x.rb,perl x.pl,php -f,pwsh -File,npx tsx,go run x.go; - a shell given the file:
bash x.sh,sh < x.sh,source x; - a program named by a path:
./x,bin/x; - inline code importing a module the session wrote:
python3 -c 'import tool'; - all of these through
env,time,bash -cand the other wrappers OpenMoat reads.
A file counts as written by the session when the session wrote it by a path OpenMoat can see: the agent’s file tools, apply_patch, an MCP tool’s file argument, a shell write (echo … > x.sh, tee, cp, mv), or a one-liner that writes it.
Example
Section titled “Example”The agent writes x.py with its file tool, then runs it:
python3 x.pyOn Gemini CLI the second call needs review, with the message above. Before 0.11.0 it was allowed. The same holds for a script the shell writes, in one command line or two:
echo … > x.sh; bash x.shcat > y.sh <<EOF … EOF; sh y.shNot affected, because the session did not write the file or the command runs the project’s code by design:
python manage.py # a file the session did not writepytest # test runners, build tools, package scriptsnpm testcargo testCommands
Section titled “Commands”| Command | What it does | Example |
|---|---|---|
openmoat policy upgrade |
Takes the session-written-code rule into a policy written before 0.11.0 |
openmoat policy upgrade |
openmoat allow --last |
Look at the script, then approve the command for the session. It holds until the agent writes the file again | openmoat allow --last |
openmoat status |
Shows whether each agent has hook + OS sandbox (no review) or hook only (review) |
openmoat status |
openmoat run -- <agent> |
Puts the whole agent in one sandbox, so the review does not apply | openmoat run --write ~/.claude --write ~/.claude.json -- claude |
openmoat allow --last --always refuses this review: a permanent rule cannot vouch for code the agent may rewrite.
What OpenMoat records
Section titled “What OpenMoat records”To know which files a session wrote, the audit log (schema 5 from 0.11.0) keeps, per agent session, each file it wrote by a literal path. The record keeps 30 days and the newest 100 000 files; a file whose row is gone counts as one the session did not write. An older OpenMoat refuses a schema-5 log, so keep one OpenMoat installed.
Limits
Section titled “Limits”- Test runners, build tools and package scripts (
pytest,npm test,cargo test,make,go run .) running files the session wrote do not need review. - Files another session or a person wrote do not need review.
- Files written where the hook cannot see it do not need review: the files
tar xorunzipextract, a build’s or a package manager’s output, what a script the agent wrote writes in turn, a download saved under a name the command does not show, a copy made inside a script. - Code a program loads on its own (
import helperof a writtenhelper.py,require('./lib'), aconftest.py, a git hook) is not seen, nor a program named through a variable whose value the line does not show. - Shells OpenMoat does not parse (PowerShell,
cmd) defer to the agent. - A flag that turns a sandbox off at start (Codex’s
--sandbox danger-full-access) is not seen: the sandbox state is read from the agents’ settings, asopenmoat statusreads it.
Inline code that builds the names it opens has its own rule: Inline code with built names. The full list: Limits and THREAT_MODEL.md §5.