agentleFS
rjstonerjstone/agent-skills/skills/sandboxing/SKILL.md

sandboxing

Skill0 starsChanged 4 days agoMITView on GitHub

Use when running a nested agent CLI (opencode, codex, another model), a test harness or an untrusted-but-cooperative script on Linux that must not see your environment variables, API keys, other processes or files outside its own folder, or must not damage files it wasn't given - "run it so it can't read my keys", "keep the tested model away from my home folder", bubblewrap/bwrap.

  • Reads credentials
  • Deletes or force-pushes

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No shell for the tested model: when narrow tools will do (a read-only docs tool, a fixed command).

    line 21
  2. Very specific:

    Keep real keys outside: Use an egress proxy that injects credentials, or a key file read only by the caller.

    line 23

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Sandboxing

Not for hostile code. This keeps a cooperative program (a nested agent, a test harness) from wandering: reading your keys or files by accident, sending them to an inference provider, or rm -rf-ing the wrong folder. Code that is trying to escape needs stronger isolation: see references/limits.md.

Cheapest protection first

  1. No shell for the tested model when narrow tools will do (a read-only docs tool, a fixed command). Nothing to sandbox.
  2. Keep real keys outside. Use an egress proxy that injects credentials, or a key file read only by the caller; inside, set placeholder keys (--setenv OPENROUTER_API_KEY=placeholder).
  3. Then the sandbox for whatever still runs commands.

Quick start

python3 scripts/leak_test.py        # once per machine: must print PASS
python3 scripts/sandbox.py --check  # what a sandboxed command sees
python3 scripts/sandbox.py --work /tmp/run1 --ro /opt/node \
    --setenv OPENROUTER_API_KEY=placeholder -- CMD [ARGS...]

scripts/ is relative to this skill's folder. Exit status is the command's (a signal gives 128+N; under timeout, 124). sandbox.py's own errors (bad option, preflight, missing tool) exit 125, as env and timeout do, with a sandbox.py: error: line on stderr saying what to fix; check that line when the command itself might exit 125. --show prints the full bwrap command without running it.

Inside, the command sees: an empty environment plus HOME=/work, PATH, LANG, TMPDIR=/tmp, the caller's proxy variables and the CA variables; uid 1000; read-only /usr, /etc/ssl; private /proc, /dev and /tmp; /work (writable) and only the binds you add.

OptionEffect
--work DIRwritable folder at /work (also HOME and the cwd); default: a new private (mode 700) folder in /tmp, removed afterwards unless --keep
--cwd DIRworking directory inside, relative to /work (e.g. --cwd proj); must exist
--ro SRC[:DEST], --rw SRC[:DEST]read-only / writable bind (repeatable); SRC/bin of a --ro bind goes on PATH
--setenv NAME=VALUE, --pass-env NAMEset a variable inside; copy one of yours in (readable inside: never a real key)
--no-netno network; default is shared network with your proxy variables and a CA copy at /ca.crt
--mem MB, --nproc N, --cpu SEClimits (prlimit); --mem caps address space, not memory use
--user NAMEhost user when started as root (default sandboxer, created if missing)

Gotchas

  • Started as root, bwrap runs as the sandboxer host user (setpriv), and --work is chowned to it. Every bind source must be readable by that user: a root-only parent (an agent's scratch folder) fails preflight with the folder's name. Copy the data under /tmp (chmod -R a+rX) instead. A --rw source must also be writable by it (preflight says so otherwise); files made there belong to sandboxer on the host.
  • --mem and Node.js: --mem limits virtual address space, and V8 reserves a lot of it at startup, so Node (and opencode's runtime) dies below about 768 MB ("Failed to reserve virtual memory", exit 133/134) while using far less. Use --mem 1024 or more for Node-based commands; sandbox.py warns.
  • Runtimes outside /usr (Node.js under /opt, a venv): bind the runtime's folder with --ro; its bin/ is then on PATH.
  • HOME=/work: config goes in /work/.config/...; put it in the work folder before the run. /tmp is private and gone after the run: write results to /work and read them from outside.
  • Refused binds: your home, /root, ~/.ssh, ~/.aws, ~/.config/gh, ~/.claude, ~/.codex, ~/.local/share/opencode, or a folder holding them. Bind a narrower folder (--allow-sensitive overrides; don't).
  • Proxy URL with user:password@ is refused, since it would be readable inside (--allow-proxy-credentials overrides).
  • No /etc/passwd: whoami fails and git needs user.name/user.email set. /etc/hosts is a minimal one (localhost only, not the host's file, which may name internal hosts); --ro /etc/hosts binds yours instead.
  • Everything you bind or pass in is readable by the command: that is the boundary.

Read when needed

  • references/nested-agents.md: running opencode (or any agent CLI) inside, with placeholder keys and JSON output.
  • references/limits.md: threat model, what this does not protect, stronger tools.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.