Docs menu

Documentation / Sandbox

Secrets

Keep .env files, keys and API tokens away from your coding agent. Hide secret files, find secrets left in code, and give the box a fake value in place of each API token.

On this page

Overview

Your project holds secrets of its own: .env files, private keys, API tokens. co:op keeps them out of the box in three ways:

coop doctor checks that hiding works on your computer. See what it checks.

Hidden files

A normal coop run, coop loop or coop shell mounts your whole working tree. co:op hides the files and folders on its built-in list. The box can see that a hidden file exists, but can't read it. How the box treats common names:

Files and folders Example In the box
.env, .env.* .env.production hidden
*.tfvars infra/prod.tfvars hidden
*.pem, *.key, id_rsa* certs/server.key hidden
secrets/, .ssh secrets/stripe.json hidden
dotfiles ending in secrets .shell-secrets hidden
config files called secrets secrets.env, secrets.yml hidden
source files and docs secrets.go, secrets.md readable
public certificate bundles cacert.pem readable
templates ending in .example, .sample or .template .env.example readable
key files, even as templates id_rsa.example hidden

.gitignore doesn't hide files from the agent. A Git-ignored file such as serviceAccount.json stays readable in the box unless the built-in list or .coopignore hides it.

Your own paths: .coopignore

The built-in list can't know where your repo keeps its own secrets, such as live keys in config/stripe.live.json. List those paths in a .coopignore file at the repo root, one pattern per line:

# every prod.yml, at any depth
prod.yml
# a path from the repo root
config/stripe.live.json
# the .yml files directly in config/
config/*.yml
# every vault folder, with its contents
vault/

Patterns can use *, ? and [...] within one path segment, but not the ** or ! of .gitignore. A comment needs its own line: prod.yml # note is one pattern, comment included.

A path without wildcards, such as config/stripe.live.json, also hides every file or folder called stripe.live.json below that .coopignore. Renaming config/ therefore can't reveal the secret.

A .coopignore applies below its folder, including to nested repositories such as submodules and Git worktrees. co:op also reads the .coopignore files in the folders above the project, except in your home folder and the folders that contain it, such as /. An agent that creates sub/.git therefore can't reveal sub/secret.yml to a new box started in sub/.

To share rules across projects, put a .coopignore in a folder above them, such as ~/Projects/.coopignore. Paths in that file start from its folder:

# ~/Projects/.coopignore
# hides config/*.yml in the ~/Projects/app project
app/config/*.yml

co:op ignores ~/.coopignore, and a .coopignore in a folder that another user owns, such as /tmp.

If a box moves a hidden file or folder to a path that no rule matches, such as a file hidden by config/*.yml after mv config cfg, later boxes and co:op's commands still hide it there. At its original path, the current rules decide whether it is visible.

coop fork merge refuses a change to a hidden file unless you pass --force. A merge from an isolated fork always refuses it.

A .coopignore must be a readable regular file of at most 1 MiB. If an invalid .coopignore could hide a file that no other rule hides, co:op refuses to start the box.

SSH keys and agent forwarding

We don't recommend giving an agent SSH access. Once the agent signs in to a server, it works outside the box: it can do anything your account on that server allows, and co:op's file and network rules don't apply there. For servers, we recommend emisar. emisar gives the agent only the actions it needs, such as reading container logs, without your SSH key, and can ask you before a change like a restart. For Git, HTTPS with an API secret is narrower: a fine-grained token can push to one repository and nothing else.

co:op hides .ssh folders in your project and never gives the box your SSH agent. If a run still needs SSH, allow it one server at a time.

Example: sign in to a server

Say an agent should check logs on deploy.example.com as the deploy user.

  1. Make sure your key is in your SSH agent:

    Shell examples

    ssh-add -l                  # the keys it holds
    ssh-add ~/.ssh/id_ed25519   # add one
    
  2. Add the server to .agent/project.yaml:

    YAML

    box:
      ssh:
        - host: deploy.example.com
          user: deploy
    
  3. Run coop approve and confirm the server, the user and your key. Then confirm the server's host keys, which co:op reads from the server and compares with your ~/.ssh/known_hosts.

  4. Start a run. ssh works in the box as usual:

    Shell examples

    coop run -- ssh deploy@deploy.example.com \
      'tail -n 50 /var/log/app.log'
    

After that, every run in this project can sign in to that server until you remove it from box.ssh. After any change to the list, runs don't start until you run coop approve again.

For GitHub, add this entry, and git push over SSH works in the box:

YAML

box:
  ssh:
    - host: github.com
      user: git

Every field is in the box.ssh reference.

To allow a server for one run without saving anything, pass --ssh to coop run, coop shell or an agent command, and confirm the server's host keys when the run starts. Add :<port> for a port other than 22, and repeat the option for more servers:

Shell examples

coop claude --ssh deploy.example.com

How it works

Your key never enters the box. The box gets an SSH agent run by co:op. That agent passes a sign-in to your own SSH agent only when:

  • the sign-in goes to an approved server
  • the server shows the host key that co:op recorded
  • the user matches the entry's user:, if it has one

Everything else is refused:

  • other servers
  • adding or removing keys
  • forwarding the agent with ssh -A
  • signing anything that isn't a sign-in, so commits can't be SSH-signed in the box

coop net inspect shows every sign-in and refusal, and coop net blocked <host> explains a refusal.

Rules and limits:

  • Use the server's host name, not its IP address. In a filtered run, co:op's gateway connects to the server by that host name (see SSH in filtered runs), and a server on a private address needs an open run. If you only know the IP address, try the host name that dig -x <ip> prints.
  • If your SSH agent holds more than one key, set key: to the one to use.
  • If a server's host key changes, set host_key: to the new fingerprint and run coop approve.
  • Offline runs, remote sessions and Apple's container runtime get no SSH agent.

What an approval still allows:

  • A sign-in opens a whole session: a shell on the server, and connections from that server to other hosts through ssh -D, -L, -W and ProxyJump.
  • On GitHub, the approval applies to every repository your key can push to, force pushes included.
  • Every server that shares a recorded host key is approved too.

Mounts, environment variables and MCP servers you add can give the agent more access. Keep folders that hold keys or tokens out of the box, and give the agent tools limited to the actions it needs. See how to connect MCP servers.

Secrets inside files

co:op hides whole files, so a token pasted into an ordinary file stays readable. coop secrets find scans for known provider tokens, private keys and long random values assigned to variables like API_KEY or PASSWORD. It reports each finding as file:line and exits 1 when it finds one, so it works before a run and in CI:

Shell examples

coop secrets find
coop secrets find --include-ignored  # also files Git ignores

The report never shows a value. In a project that hides config/stripe.live.json with .coopignore, the scan still reports the key in it:

✗ 1 possible secret found

  config/stripe.live.json:2
    Stripe key
    Hidden from the box, but Git would commit this file.

Remove real secrets from files you intend to commit.
If this is a false positive, add this entry to .coopsecretsignore
and replace <reason> with an explanation:

  # config/stripe.live.json — Stripe key
  fp-v1:01e7bb5857e09cfa0f03f0785ddbaed4cd8c0c11945566069d0709fc0df27dd4 # <reason>
  • The default scan reads the files Git would commit, hidden ones included, because hiding a file from the box doesn't stop you from committing or pushing it. It also reads co:op's Git-ignored task files and notes under .agent/.
  • --include-ignored adds the other Git-ignored files the box can read, except those in dependency and build folders such as node_modules, vendor and dist.
  • If the scan can't read a file, it fails, so a permission error can't produce a clean result. If it can't open a folder, the default scan warns that the files Git doesn't track in that folder weren't checked, and --include-ignored fails.
  • The command also lists changed files that can run commands on your machine, such as commit hooks, editor or agent settings, Compose files and the Makefile. With --include-ignored it also lists such files that Git ignores, like .claude/settings.local.json. Read them before you run anything. This list never changes the exit code.

After a change to the Makefile, for example, the scan ends with:

Review files that run commands
  Makefile
    Runs when you use make.

  Read these changes before running your tools.

For a false positive you've reviewed, copy the entry the scan prints into .coopsecretsignore at the project root and replace <reason> with your reason. Here a test fixture holds an expired token:

# test/fixtures/expired-session.json — JWT
fp-v1:f144933b669bf2af2af27f0cb621255d178e6762edc3c6f6fa7216f88d0f3b8b # expired test token

The next scan passes:

✓ No new possible secrets found
  1 finding ignored by .coopsecretsignore.

An entry without a reason, or with <reason> left in, stops the scan with the line to fix. The entry identifies that exact finding without storing the secret. Adding a line above the finding doesn't invalidate the entry, but changing the value or moving the file does. The entry applies only to this command: fork merges, checkpoint uploads and session redaction still check every finding.

API secrets

When the app you're building needs a real API token, such as GH_TOKEN for GitHub, save it with coop secrets add instead of keeping it in a file. Inside the box, the GH_TOKEN environment variable is set to a fake value. co:op replaces it with the real token in the request headers, but only on requests you approved. An agent that prints the variable, or sends it anywhere else, reveals only the fake value.

Example: gh api

Say your scripts read issues with gh api. Save the token once, followed by every host it may be sent to:

Shell examples

coop secrets add GH_TOKEN api.github.com

Type or paste the value at the prompt:

GH_TOKEN:
✓ Saved GH_TOKEN for api.github.com

List the requests it may be used for in .agent/project.yaml, then run coop approve:
  box:
    secrets:
      GH_TOKEN:
        - GET https://api.github.com/**

co:op saves the value in ~/.config/coop/secrets.json, which no box can mount. A project can't add hosts to that list. The printed line allows every GET request to the API. Narrow it to the requests your scripts make, and approve them:

YAML

box:
  secrets:
    GH_TOKEN:
      - GET https://api.github.com/repos/acme/app/**

Shell examples

coop approve

Now gh works in the box as usual. It sends the fake value in its Authorization header, and co:op replaces that with the real token because the request matches the approved line:

Shell examples

coop run -- gh api repos/acme/app/issues --jq '.[].title'

The variable holds only the fake value:

Shell examples

coop run -- sh -c 'echo $GH_TOKEN'
coop_decoy_GH_TOKEN_…

co:op refuses a request that isn't on the list, such as gh api -X DELETE repos/acme/app, with a 403 that shows the line to add.

gh isn't in co:op's base image. Add it to your .agent/Dockerfile (apt-get install gh on the Debian base) and run coop build.

Push over HTTPS

Git in the box can push to github.com with a saved token. Save the token for github.com, list the two requests a push makes, and run coop approve:

Shell examples

coop secrets add GH_TOKEN github.com

YAML

box:
  secrets:
    GH_TOKEN:
      - GET https://github.com/acme/app.git/info/refs
      - POST https://github.com/acme/app.git/git-receive-pack

co:op sets a Git credential helper for https://github.com in the box. The helper answers with the user x-access-token and the fake value, and co:op replaces the fake value with the token on these two requests. To fetch with the token too, add POST https://github.com/acme/app.git/git-upload-pack. The paths follow the remote URL, so use an https://github.com/acme/app.git remote. We recommend a fine-grained token limited to that repository, with Contents write, so the token can't change anything else in your account.

The helper works for github.com only. Keep the Git lines for github.com under one secret. When two secrets have them, Git gets no credential.

Which requests a line allows

Each line is a method and an https URL. The method is GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS or ANY. A line matches any query string:

Line Allows
GET https://api.github.com/repos/acme/app GET and HEAD requests to that path
POST https://api.github.com/repos/acme/*/issues POST requests where * is one path segment, such as web
GET https://api.github.com/repos/acme/app/** GET and HEAD requests to that path and every path below it
ANY https://api.github.com/** every GitHub API request, with any method
GET https://*.example.com/** GET and HEAD requests to one label under example.com, such as eu.example.com, as in network rules. Save the secret for *.example.com too.

A project can list up to 16 secrets, 64 lines per secret and 32 hosts in total.

coop approve records each secret's requests with the project's network approval. After you change the list, filtered and open runs don't start until you approve it again. Offline runs don't use secrets. A remote session gets its secrets from its controller. See the session API.

Change or delete a saved secret

Shell examples

coop secrets                               # names, hosts and use
coop secrets add GH_TOKEN api.github.com   # a new value and hosts
coop secrets rm GH_TOKEN

coop secrets shows each secret's hosts, never its value, and how runs on this machine used it: how many requests carried it, when the last one did, and how many requests co:op refused. Saving a name again replaces its value and hosts.

coop secrets rm asks first, because co:op can't show or restore the value. Running boxes keep the value until they stop. A project that still lists the secret in box.secrets doesn't start until you save the secret again, or remove it from box.secrets and run coop approve.

What happens to a request

In filtered and open runs, co:op's broker reads every request the box sends to a host listed in box.secrets. Clients reach the broker in two ways: the box's /etc/hosts points each exact host at it, and clients that use the box's HTTPS_PROXY are sent there too. co:op adds the run's certificate to the box's system certificate list and points Python's requests at it.

  • If a request carries the fake value in a header and a line approves it, the broker sends it with the real value. In the Authorization header, the broker also replaces a fake value inside a base64 token, such as Basic auth.
  • If no line approves it, the broker refuses the request with a 403 that shows the line to add. In a filtered run, coop net blocked lists the refusal.
  • A request without the fake value is sent when a line matches it or the run may reach the host anyway. In a filtered run, a line allows its requests without a network rule.
  • In a response, the broker replaces the real value with the fake value, and a re-encoded Authorization token with the one the box sent. Range requests are sent without their range, so a value can't come back in pieces.

The fake value stays the same for one project on one machine, so a token your app saved in its development data keeps working.

What it doesn't cover

  • The broker replaces the fake value only in headers. A token sent in a URL or a request body arrives as the fake value.
  • A signed request, such as AWS SigV4, is computed from the secret, so the fake value can't sign it.
  • A WebSocket or other upgraded connection can't use a secret. A response that co:op can't decompress is refused when its request used a secret, because co:op can't check it for the real value.
  • Project services don't get API secrets.
  • /etc/hosts can't hold a wildcard host such as *.github.com, so only clients that use HTTPS_PROXY reach the broker for it. For Node's built-in fetch, set NODE_USE_ENV_PROXY: "1" in box.env.
  • Point clients that ship their own certificate list, such as Java or Elixir's CAStore, at /etc/ssl/certs/ca-certificates.crt. An image that isn't built on co:op's base image keeps its system list unchanged, so point clients at $SSL_CERT_FILE there.
  • In an open run of a project that lists port 443 in serve.ports, the box keeps that port, so its secret hosts are reached only through HTTPS_PROXY.
  • A response that repeats the real value in another encoding, such as hex, reaches the box.
  • A run refuses a secret for a host that its agent signs in to, such as api.openai.com in a Codex run. Other agents' runs can use it, and a host an agent only downloads from is allowed.
  • The agent can still do everything the approved requests allow, so give the token only the access your app needs.

How hiding works

co:op hides files in one of two ways. eBPF protection denies access to a hidden file in the kernel. Mount protection mounts an empty read-only file or folder over it. co:op uses eBPF protection when all of these hold, and mount protection otherwise:

  • The box runs on Docker, without rootless mode or user-namespace remapping, and without container options that conflict with the protection.
  • The project is on APFS on a Mac, where the Docker VM enforces the rules, or on ext4 or xfs on Linux.
  • Docker uses cgroup v2 with the cgroupfs or systemd cgroup driver. With systemd, co:op asks systemd over the system bus for the cgroups that hold its boxes.
  • The kernel runs the BPF security module (BPF LSM) and has every file hook the filter attaches to. Recent kernels such as Fedora 44's do, and older ones such as RHEL 10's 6.12 don't. If the module is off, add bpf to the lsm= boot parameter.

coop doctor reports why a project gets mount protection, and tries to read test secrets in a real box. A launch doesn't test the protection, so run coop doctor after you update Docker or OrbStack. co:op builds the eBPF helper inside Docker, so you don't install any packages on the host.

What the box sees with eBPF protection

With eBPF protection, the box can't read or change a secret, including through another letter case, an equivalent Unicode spelling, a symlink or an existing hardlink. Each attempt returns Operation not permitted. The box also can't connect to a Unix socket in a hidden folder, such as one another container serves from the project. Public files stay writable, ordinary public hardlinks work, and .coopignore is readable but can't be changed.

Some tools stop at that error, such as Terraform when it opens terraform.tfvars. To keep them working, each hidden file that exists when the box starts, up to 1,000 per launch, shows up as an empty read-only file instead. In a Git repository, only Git-ignored files do, because an agent's git add -A would commit a tracked or new file as empty. So add your secrets to .gitignore. The box can't delete or rename a folder that holds one of these files.

stat works on the other hidden files, so find and tools that list a folder keep working:

On a hidden path Result
stat on a file the file's real size, times, mode, owner and link count
extended attributes of a file read as empty
readlink on a symlink fails
stat on a folder, or on anything inside it fails
ls -l in the folder's parent shows the folder's entry with an error

The filesystem protection contract says how eBPF protection treats files that you create or edit after the box starts.

Tools that scan the project

For tools that scan the repository, co:op sets COOP_BOX=1 inside the box. When it is set:

  • Skip paths that return a permission error (EPERM or EACCES) on metadata lookup, folder traversal or file reads, including a denied folder's subtree.
  • Treat a denied path as unreadable, not as an empty file.
  • Report the skipped paths, so the result shows which files were checked, and keep reporting other errors.

A successful stat, or a path in the list of tracked files, doesn't mean the contents can be read. The box has no list of hidden paths, so handle the filesystem error instead of reproducing the hiding rules.

What the box sees with mount protection

With mount protection, stat on a secret shows the size and times of the empty file or folder, not the real ones. On a case-insensitive disk, co:op also mounts an empty file over every uppercase and lowercase spelling of a hidden filename with up to 11 letters, and over every spelling of .coopignore.

Mount protection hides only what exists when the agent or service starts. A secret you create on the host later at a public path, such as a new late.pem or .env.local, is readable in that box until it restarts. A file created inside an already hidden folder is not, because the box sees only the empty folder. So create secrets before you start an agent, keep them in a hidden folder such as secrets/, or restart the agent after you add one. The box can't rename a hidden folder. It can rename a folder that holds a hidden file, and the file stays hidden at its new path.

When mount protection can't cover a filename

A filename with more than 11 letters or a non-ASCII letter, or a project with too many spellings in total, exceeds what co:op can mount. The box or service could then read the file under another letter case, so co:op refuses to start the agent or service. To fix it, either:

  • move the file into a hidden folder, or
  • run coop approve --case-exposure to review the listed files and accept that they stay readable under another letter case with mount protection. Plain coop approve reviews network access and doesn't accept any file exposure.

The approval applies to those exact paths, including their future contents, for new agent and service runs. A newly exposed path needs another approval, and running boxes don't change. .coopignore can't be approved this way. COOP_ALLOW_CASE_EXPOSED_SECRETS=1 exposes the files for a single run. With eBPF protection, these files stay hidden and need neither.

Filesystem protection contract

This contract describes eBPF protection. Mount protection hides only what exists at start, as described above, and a launch that uses it says so under "Protecting secrets".

co:op trusts the host and your editors. Each time co:op starts an agent or service with eBPF protection, it records the current hiding rules and the protected files and folders. While the box runs, it checks every file the box opens against the built-in list. As a result:

  • Ordinary edits to public files work immediately.
  • A path that is already protected stays protected when you edit it or save it atomically on the host, even when a parent folder is replaced. Existing hardlinks keep their protection when the original file is replaced.
  • A new file that the built-in list matches, such as late.pem or .env, is unreadable in the box as soon as it exists, in any letter case or Unicode spelling. The box can still create, overwrite, truncate or delete such a file, so installers and key generators keep working. The box can't read the file, rename it, or rename another file to a matching filename. So a tool in the box that saves a new secret by writing a temporary file and renaming it fails with Operation not permitted. Writing the file directly under its final name works.
  • Inside a hidden folder, the box can't create a file or folder, or move a file in.
  • Restart the affected agent or service after you change .coopignore, create a file that only .coopignore hides, create a hidden folder, mark an already-public file or folder as secret, or create an unprotected hardlink to a secret from the host. Protection that is already running doesn't reload its rules or revoke memory mappings that were already readable.
  • On the host, to save a secret atomically, write the temporary file outside the project or inside an already hidden folder. A new temporary file at a public path is protected only when the built-in list matches its filename.
  • Protection belongs to the file or folder, not to its path. Removing the hiding rule doesn't make a hidden secret public while it still has another hardlink in the project. Remove the other hardlinks and restart before you make the original file public.
  • When you approve a hidden file for a service, the service can read that file, its other hardlinks and your later in-place edits on the host. The approval never allows writes. If the file is replaced, start the service through co:op again so that it can read the new file.

A separate helper enforces the rules in the kernel, and the agent gets no BPF privileges. If the helper exits, all access to the shared project files is denied until co:op removes that agent or service. On Linux the denial applies to the whole disk that holds the project, so the box usually can't run its own programs either.

Stopped service containers keep their protection for a later restart. After a VM reboot, co:op's guard runs before an image's start command and its healthchecks, and refuses to run image code under the old protection. Start the service through co:op to get new protection.

The helper on AppArmor hosts

With the systemd driver, the helper talks to systemd over the system bus. Docker's default AppArmor profile blocks that, so on an AppArmor host such as Ubuntu the helper runs without AppArmor. To run the helper under co:op's own profile, run this once:

Shell examples

coop setup apparmor

coop doctor suggests the command when it would help, and again when an update changes the profile. The command installs the profile in /etc/apparmor.d through Docker, without sudo, and the profile loads on every boot.

The profile has Docker's default rules, which deny mounts and writes to kernel settings, plus the two systemd calls that start and stop co:op's slices. Other system bus calls stay blocked. AppArmor can't check the arguments of those two calls, so the profile doesn't limit what the helper could do through systemd.

View this page on GitHub