Run an agent or any other command under a macOS sandbox that:
- Confines filesystem access
- Lets the command propose changes to safe write targets as patches you review outside the sandbox
- Restricts outgoing network connections to allowed hosts
- Restricts git pushes to allowed repos (currently GitHub only)
- Hardens git internals
This is not a container- or VM-based solution. Chopi runs the command directly on your machine with your real tools and environment, using the OS's native sandboxing and additional network proxies to put guardrails around it.
Chopi uses Agent Safehouse for building most of the underlying macOS Seatbelt policy, Smokescreen for its CONNECT proxy, and Caddy for its GitHub reverse proxy.
Clone the repo and run the installer:
./install.shBefore first use, review the configuration.
The network config, config/network.yaml, sets what the session's proxy lets through:
allowed_domains: # the hosts the proxy allows; "*.example.com" for subdomains
- pypi.org
global_deny_list: # hosts the proxy denies even where allowed, without an alert
- "*.datadoghq.com"
github_allowlist: # repos the relays use your GitHub token for: push, private repos
- owner/repo
- owner/*Listing a host in global_deny_list keeps its blocked requests (telemetry, auto-updates etc.)
from spamming you with notifications.
Edits take effect immediately, even in a running chopi session. When you change
github_allowlist, or save the file with no edit, the session's proxy also takes up any GitHub
token that gh has replaced since the session started.
That file applies to every project. To allow a host or a repo for a single project, put it in
that repo's own network config instead. The repo's network config adds to the base one, for the
repo's sessions alone. It lives in ~/.chopi/config/workspaces/, in a dir named for the repo's
path, every character but a letter, digit or dash made a dash (as Claude Code names its project
dirs; a very long one is cut short), then a digest of the path, telling apart repos whose paths
would otherwise name the same dir. A session sets $CHOPI_WORKSPACE_NETWORK_CONFIG to the path
of the repo's network config, and Claude is told to quote that path when it suggests adding to the
file. chopi --config-paths, run anywhere in the repo, prints the path too. E.g. for
~/dev/myapp:
~/.chopi/config/workspaces/-Users-me-dev-myapp-1a2b3c4d5e6f7a8b/
sandbox.sh # the repo's own sandbox config, see below
network.yaml # the repo's own network config, in the base one's format
The repo's network config is optional. It takes effect immediately, even when created or deleted
mid-session. It takes the same keys as the base one, and chopi refuses any other key. It can add
hosts and repos, or deny hosts. Either file's global_deny_list denies its hosts even where the
other file allows them.
A mistake made in the repo's network config mid-session never stops a running session: the edit
doesn't take effect, as the notification says, and what the file added before it stays. An edit to
the base config still takes effect, with what the file last added. But a mistake keeps a new
session from starting, as a mistake in the base config does, so that the repo's sessions all run on
the same config; so does a file chopi won't read -- a symlink, one with other hard links, or one
it can't read. The repo's worktrees, chopi --worktree ones included, share its config. When a
repo has its own, chopi says so as a session starts. Like the base config, it's outside every
workspace, and no sandboxed command can change it.
To configure the sandbox policy, edit the first two settings in config/sandbox.sh (other
settings can be reviewed later):
CHOPI_SAFEHOUSE_FLAGS:safehouseflags for selecting what preset features and additional filesystem access to enable in the underlying macOS Seatbelt policy; runsafehouse --helpfor the full list of flags and additional ways to configuresafehousewhich also take effect here.chopialso automatically appends its network protection Seatbelt policy (always last, so it has the final word on network access).CHOPI_EXTRA_ENV: extra environment variables for the sandboxed command, passed as literalKEY=VALUEafter the--. Use it for vars whose values are fine to be visible for inspection on the command line. You can also forward a host value here withFOO="$FOO". For secrets or anything you'd rather keep off the visible command line, usesafehouse's flags--env-pass NAME(forward a host var by name) or--env=FILE(source an env file) inCHOPI_SAFEHOUSE_FLAGS.CHOPI_SAFE_WRITE_TARGETS: paths you'd like to allow writing to from inside the sandbox, but which can't be simply trusted to be written by an agent in auto mode, requiring review outside of the sandbox. See Safe write targets below.
Edits to config/sandbox.sh take effect on any following chopi invocations.
config/sandbox.sh applies to every project. To grant a path, or set an env var or git config, for a
single project, put it in that repo's own sandbox.sh instead, in the repo's own config dir (see
above), which adds to the base config for its sessions alone. chopi --config-paths prints its
path, and a session has it in $CHOPI_WORKSPACE_SANDBOX_CONFIG. It's bash, like the base config, and
may only add to CHOPI_SAFEHOUSE_FLAGS, CHOPI_EXTRA_ENV and CHOPI_GIT_CONFIG.
It's sourced in a bash of its own, with those arrays empty, so assigning one adds to it just as
appending does. E.g.:
CHOPI_SAFEHOUSE_FLAGS=(--add-dirs-ro "$HOME/data/myapp")
CHOPI_EXTRA_ENV=(MYAPP_DATA="$HOME/data/myapp")Setting any other CHOPI_ variable (safe write targets, the proxy config, worktree setup) is
refused, as is a failing command; those stay in the base config. Like that one, it takes effect as a
session starts, not mid-session. A mistake in it, or a symlink or a file with other hard links,
keeps a session from starting.
Both configuration files are created once on install and then never overwritten, so any
edits persist on reinstalls. When updating Chopi, you can examine the templates under
config/templates for any upstream changes that you might want to bring in to your local
configuration.
-
Run your command under the sandbox, at the root of the repo you're working on:
cd ~/path/to/your/repo chopi <executable> [args...]
The sandbox grants read/write to your current directory (the workspace) and runs the command there. The workspace must be the root of a git worktree, where
chopi's git protections apply; running anywhere else (a subdir, or a non-git directory) is refused, so you can't accidentally run "naked" without them.Each
chopisession starts its own outgoing proxy and stops it when the command exits. Each refused connection pops a macOS notification naming the host; click it while it shows to open the session's proxy log in your editor ($VISUAL, else$EDITOR) if it's a GUI one like VS Code, and in macOS's default text editor otherwise. (If the banners don't appear, allow notifications for your terminal in System Settings -> Notifications.) Hosts matching the known denylist are the exception: their denials log a single quietdeny(known)line per session, with no notification. The logs are kept under~/Library/Logs/chopifor two weeks;chopi --verboseprints the session's log path, and also has the log include smokescreen's raw output.To run a sandboxed command in a separate git worktree instead of the repo root, you can either
cdto an existing worktree and launchchopias usual, or add and setup a new worktree by runningchopiin--worktreemode:chopi --worktree NAME <executable> [args...]
Run from the root of the repo (or a worktree), this creates a new linked worktree at
<repo>/.worktrees/NAME, checks out branchNAME(creating it in case it doesn't already exist), and runs the command with that worktree folder as its workspace. Or, if the worktree at that path already exists, it is reused (on whatever branch or detachedHEADit has checked out), so you can resume previous sessions.In both normal and
--worktreemodes,chopialso iso 8000 lates the command to a single worktree and applies additional hardening to prevent rogue commands compromising the host system.The workspace is always the root of a git repo (main worktree) or a linked worktree (including
--worktreemode).chopiisolates access to that worktree, which keeps an agent from wandering outside its assigned task and picking up irrelevant information from another worktree. This undoes safehouse's own default grants to all other worktrees. Forclauderuns only, read access is also granted to specific allowlisted Claude context files (currentlyCLAUDE.md, also under.claude/) in folders above the repo. Their symlink targets and@-imports are NOT granted automatically: before launchingclaude,chopifollows them inside the sandbox and refuses to run while any is unreadable, listing the denied paths so you can grant the reads yourself viaCHOPI_SAFEHOUSE_FLAGS.In addition,
chopihardens the repo's git internals:.gitstays readable, but only git's data paths (objects, refs, index, etc.) are writable. Everything else (config,hooks, etc.) stays read-only, so the sandboxed command can't plant code that could later run unsandboxed on some git operation. Submodules (recursive) get the same treatment one level down.Operations that write to the denied paths fail inside the sandbox: repo-local
git config,git remote add,git worktree add,git submodule update(git insists on rewritingcore.worktreein the submodule's read-only config), and hook installers (e.g. husky), so run these outside the sandbox. For--worktreeruns,chopiprovides theCHOPI_WORKTREE_SETUPconfig to set commands to run before the sandboxed command starts. The default initializes and updates submodules and pre-sets the upstream forpush/pull(push -ucan't write the upstream to the config while sandboxed).The writable data paths in the common git dir mean the worktree isolation isn't perfect and agents still have access to, e.g., objects and refs only used in other worktrees; but the worktree isolation's goal is more about minimizing agent errors anyway.
Hardening-wise, being able to write internal data that another worktree references is certainly a risk, but it's required given git's implementation. Hardening should therefore be considered as applying to the repo as a whole, not to a specific worktree; it's not safe to assume other worktrees remained untouched by a sandboxed session.
Rather than launch a run these protections cannot cover,
chopirefuses to start and names the cause: a workspace that is not the root of a git worktree; git location overrides in the environment (GIT_DIR,GIT_WORK_TREE) or in the repo's own files (core.worktree,core.bare, a corrupt.gitentry) that make git resolve the workspace root away from where it physically is; object reads through an external store (a non-empty.git/objects/info/alternates, also in submodule git dirs); and relocated ref storage (extensions.refStoragewith a URI payload).On termination,
chopiaborts any in-progress sequenced rebase or cherry-pick: resuming one outside of the sandbox could execute rogueexeclines injected into the todo list, with no warning ingit status, and without expecting a rebase to be able to execute code unless that's a feature the user is familiar with. The abort runs inside the sandbox so anything possibly triggered by the cleanup itself stays confined. When a sequenced operation is already in progress at launch,chopiasks before proceeding ([y/N]), so its state is never lost without consent; a non-interactive run just refuses.
When running claude, chopi appends context to the
system prompt describing the sandbox, what it restricts, the session's safe write targets, and
how to guide the user.
When running codex, chopi passes --sandbox danger-full-access to Codex. macOS Seatbelt
sandboxes cannot be nested, so Codex's own sandbox would otherwise make built-in tools such as
apply_patch fail with sandbox_apply: Operation not permitted. Chopi remains the outer filesystem
and network sandbox; Codex's approval policy remains unchanged.
chopi also passes --no-daemon, so Codex runs without its shared background app-server, which
can't start in the sandbox. This needs a Codex recent enough to have the flag, and leaves the
commands that work with the daemon, such as codex agents and codex remote-control, unusable
under chopi.
Chopi supplies the sandbox context and the session's safe write
targets as Codex developer instructions. Chopi's launch-time -c developer_instructions=...
overrides the value in Codex's configuration files.
Sometimes a change should be read before it lands, for example:
- An agent that has learned something general and should write it to guidelines shared with your team, which the sandbox grants read-only.
- A persistent change to an in-workspace CLAUDE.md file.
CHOPI_SAFE_WRITE_TARGETS in config/sandbox.sh names paths of such directories/single files,
absolute or relative to the workspace dir. For example:
CHOPI_SAFE_WRITE_TARGETS=(
"$HOME/dev/team/common_knowledge"
docs # relative to the workspace root
CLAUDE.md # a single file works too
)Each named target is denied write, granted read-only access, and gets a slot in the workspace's
queue under ~/.chopi/patch-queue, where the command queues a patch using
.internal/chopi-queue-patch.sh. Agents still need to be instructed on safe write targets; chopi
currently provides such instructions out-of-the box for Claude Code (see
Claude Code Integration above).
When the command exits, chopi offers to review all patches queued in the workspace. You can also
run chopi-review at any time to review all queued patches across all workspaces. For each patch,
you are presented with the proposed message and diff, and choose to apply, reject or skip it.
Applying a patch commits it in the repo holds the target (or stops to let you resolve a conflict),
or writes it in place leaving a .orig backup if the target isn't contained in a repo. Nothing is
applied without you approving it, and chopi-review runs only out-of-sandbox.
To run the proxy against a different network config, set CHOPI_NETWORK_CONFIG in the sandbox
config to its absolute path, which must be in ~/.chopi/config. Every session denies its sandboxed
command any change to that directory, to the default file, and to the dirs above them, whichever of
them the session itself reads, even under a grant covering them. A command that could rewrite a
network config could lift its own limits, or another session's. A config file there with other hard
links refuses every session, whichever repo's it is and whether any session uses it, as writing
through one would escape the deny (CHOPI_ALLOW_SELF=1 downgrades this to a warning, as for
--config below).
To use a different sandbox config for a single run, pass chopi --config FILE. The file
must define the same CHOPI_SAFEHOUSE_FLAGS / CHOPI_EXTRA_ENV arrays as config/sandbox.sh
(plus CHOPI_WORKTREE_SETUP for --worktree runs; CHOPI_GIT_CONFIG is optional).
chopi enforces this file being outside of the workspace you're sandboxing,
so the confined command can't rewrite its own config (set CHOPI_ALLOW_SELF=1 in your
environment to downgrade the enforcement to a warning).
CHOPI_GIT_CONFIG sets extra git config for the sandboxed command, as key=value pairs
(e.g. protocol.file.allow=always). It's applied through git's GIT_CONFIG_* environment
variables, appended inside the sandbox after the environment is fully composed, so the
pairs merge with any git config you forward from the host via safehouse's
--env-pass/--env flags instead of overwriting it (in case of a conflict,
CHOPI_GIT_CONFIG wins).
chopi lives in its own directory, outside of the repos you sandbox, so a command you
run under it can't read or tamper with the sandbox's own config. chopi enforces
this, refusing to run when it finds its own folder in the workspace (and also in
the more obscure case where the workspace is within chopi's own folder).
macOS Seatbelt (sandbox-exec) can confine the filesystem and pin outgoing network
connections to an IP/port, but it cannot filter by hostname; its network rules only
understand localhost/IP. It obviously can't filter by repo, either. Filtering is
therefore split across cooperating layers:
| Layer | Tool | Enforces |
|---|---|---|
| Sandbox | safehouse (wraps sandbox-exec) |
Filesystem and preset features; the only outgoing network permitted is to the session's local proxies: smokescreen and the GitHub relay, each on a 127.0.0.1 port picked for the session, and the relay's unix socket for the gh REST API. |
| Domain-level proxy | smokescreen (CONNECT proxy) |
Of the traffic that reaches it, only connections to allowed hosts are forwarded; everything else is refused and logged. |
| GitHub repo-level proxy | caddy (reverse proxy) |
github.com git and the REST API are reached only through this relay, which scopes them to a repo allowlist: fetching/reading a public repo is unrestricted, but reading a private repo, any push, and any authenticated API access are limited to allowlisted repos. |
The sandbox makes the proxies the only way to communicate over the network.
The domain-level proxy allows communication only with trusted hosts, so a rogue agent can't connect anywhere else to exfiltrate user data. Be careful not to add innocent domains that can still be abused by an attacker for exfiltration! (e.g. pastebin.com)
The repo-level proxy exists to prevent a misbehaving agent pushing stolen code to any repo on GitHub (possibly using an attacker-provided token). It covers both git and the REST API, and keeps the host's GitHub token out of the sandbox: the relay attaches it only to requests for allowlisted repos. Currently, this protection layer only supports GitHub; other repo-hosting domains can be allowlisted by domain, but be aware of the exfiltration risk.
The sandboxed agent must route its traffic through the proxy, i.e., respect
HTTP_PROXY/HTTPS_PROXY). The sandbox blocks all other outgoing traffic, so an agent that
ignores them gets no network rather than a direct connection. Most popular CLI
harnesses (Claude Code, Codex, Gemini CLI, Copilot CLI, opencode, Pi) do this by default
on current versions; a few (e.g. Cursor CLI) need NODE_USE_ENV_PROXY=1, which chopi also
sets in the sandbox env.
Network path of the sandboxed command:
<cmd>
│ Seatbelt allows outgoing connections ONLY to the session's proxies' ports + the GitHub API relay socket
├─ github.com (git) ─── port ────▶ caddy relay ─(repo allowlisted?)─▶ GitHub
│ └─ public fetch: any repo · private fetch or push: allowlisted only
├─ gh REST API ──── unix socket ─▶ caddy relay ─(repo allowlisted?)─▶ GitHub API
│ └─ read: any public repo · authed access: allowlisted only
└─ everything else ──── port ────▶ smokescreen ─(host allowed?)─▶ api.anthropic.com / ...
└────(not allowed)────▶ refused + logged
- A network connection was refused -- Refused hosts appear as
DENYlines in the session's proxy log under~/Library/Logs/chopi(or as a single plaindeny(known)line if they match the known denylist); if the host should be allowed, add it toconfig/network.yaml. The proxy hot-reloads it, so you don't need to restart the session. An edit that loads pops a brief notification naming the file -- none means the session's proxy reads a different file (seeCHOPI_NETWORK_CONFIGinconfig/sandbox.sh). One that fails to load pops a notification that stays until you fix it, and shows in the log asNETWORK CONFIG RELOAD FAILED, with the previous config kept. The exception is an edit togithub_allowlistthat the GitHub relays fail to come up on. The edit's hosts still take effect, the relays keep serving the previous allowlist, and the next save tries again. - A
ghsubcommand fails withnot an allowed API operation,none of the git remotes ... correspond to the GH_HOST environment variable, orunable to expand placeholder in path-- Use REST forms naming the repo explicitly (-R OWNER/REPO, literal slugs ingh api repos/OWNER/REPO/...), or run the command outside the sandbox. - A non-network sandbox denial -- See Agent Safehouse's
- Debugging Sandbox Denials
to analyze, and amend
config/sandbox.sh(or anothersafehousepersistent configuration location) accordingly.
To change the default configuration a fresh install starts from, edit the templates
under config/templates.
The proxy is an in-repo Go wrapper, .internal/proxy/, that embeds smokescreen as a
library and hot-reloads its rules from the network config (the standalone smokescreen
binary only reads its rules at startup). It also supervises the session's Caddy GitHub
relays: it opens every listener itself, on ports the kernel picks, hands the relays' to
Caddy, and stops Caddy with the proxy -- including once chopi exits, however it exits.
install.sh and make build compile it to .internal/proxy/chopi-smokescreen.
Both GitHub relays live in one Caddy config: a TCP listener on a 127.0.0.1 port for git
smart-HTTP, and a loopback unix socket for the gh REST API. chopi points gh at the
socket with GH_HOST=github.localhost (which makes gh speak plaintext http, so still
no CA) plus http_unix_socket in a throwaway config dir. The host-side token is injected
only for allowlisted /repos/{owner}/{repo} requests; other repos are reached anonymously
(public read only). GraphQL (/graphql) and account-level endpoints (gists, keys,
/user) can't be scoped by URL path, so they are denied. Search can't be scoped by path
either, but code search (gh search code ... --owner OWNER) is served with the token when
its query provably stays within owners that have an owner/* entry, by a narrow query
grammar that the relay's refusal of any other search states. Of the org-level endpoints, only
the org's Dependabot alert list (gh api orgs/OWNER/dependabot/alerts) is served, with the
token, for owners that have an owner/* entry; the host's token needs Dependabot alerts read
access across the org. Downloads that the API answers with a redirect to GitHub's signed
storage (Actions logs and artifacts, release assets) are followed through the relay
anonymously. Release-asset uploads (gh release create / gh release upload) go to
uploads.github.com, which the relay serves with the same allowlist scoping.
make build # build the proxy binary (needs go)
make test # build, then run unit and integration tests
make lint # shellcheck the scripts, go vet the proxy
make check # lint, then test
[ALLOW_REPO=owner/repo] make github-relay-test # manual end-to-end test of the GitHub relay (not in `make test`)By default, chopi's refuses protecting a workspace that overlaps chopis folder;
set CHOPI_ALLOW_SELF=1 to override when deve
59F8
loping chopi.