Skip to Content
caffeine docs

Safety

Guard, sandboxes, network, tool allowlist, trust, and what caffeine does not protect.

caffeine runs agents with nobody watching. The rule it is built on: the checks decide, not the model. Prompts can ask, but only commands can enforce. Here is what caffeine enforces, and what it leaves to you.

The guard

After every step that passed (script or agent, whatever the runner), caffeine lists every file added, changed or deleted since the start of the run, and fails the run if one of them matches a protected path.

Default protected paths:

**/.env  **/.env.*  .github/**  .gitlab-ci.yml
**/*.pem  **/*.key  **/*.p12  **/*.pfx  **/id_rsa*  **/id_ed25519*
.caffeine.conf
  • Replace the list with guard.forbid in config.yaml.
  • Open specific paths for one pipeline with guard_allow:, for example guard_allow: [".github/workflows/main.yml"] for a pipeline that maintains its CI matrix on purpose.
  • A project's .caffeine.conf cannot change the guard.

In a git workspace, the files checked are the tracked and untracked ones that .gitignore does not exclude, so build output is left out. Elsewhere, every file is checked, except .git/ and .agent/. A folder with more than 100,000 files is refused: use a smaller folder or a git repo.

Changes are compared with the start of the run, not with the previous step: a protected file that is touched and then put back still counts as changed.

Sandboxes

sandbox: runs a step's processes (run:, verify:, a cmd agent, the Claude Code CLI) in a container (podman, docker) or under bubblewrap (bwrap) instead of on your machine, or the whole run in a Kubernetes pod (kubernetes). They see the workspace, the run's logs, the pipeline's files and skills, and nothing else of your home: no ~/.ssh, no ~/.claude, no config.yaml, no other runs. Credentials come in by name only, through the sandbox's env: (and, on kubernetes, pr_env: for the last step's caffeine pr alone). On podman, docker and bwrap, the workspace's .git is read-only, so a step cannot plant a hook, an fsmonitor or a filter that caffeine's git on the host would run; the git caffeine runs in a workspace ignores hooks, fsmonitor, external diffs and textconv, and a .git a step creates in a folder run in place fails the run (the next run would trust it). A cloned repo cannot pick or drop its sandbox, and sandbox_required: true refuses any step left on the host. See Configuration.

Network

network: limits what a sandboxed step can reach: none (loopback only), named host lists, or full. On podman, docker and bwrap, only none and full can be enforced; a host list, a claude step with none (it still needs the model API) included, is refused when the run starts, never silently widened. On kubernetes, none is a NetworkPolicy and a host list a CiliumNetworkPolicy (with cni: cilium), and hubble shows what they refused (network_on_deny: fail turns that into a failed run). A step without a sandbox can only have full. network_allow_full: false refuses full everywhere, and a project's .caffeine.conf can only narrow the network. <logdir>/network.log records what each step got. See Pipelines.

The tool allowlist (claude runner)

  • Only the tools in the step's allowed_tools exist for the agent, and only they are approved. Everything else is refused without a prompt.
  • Sub-agents (Agent, Task) are always disabled.
  • Only the pipeline's MCP servers are loaded.
  • After the run, any tool that ran successfully without being in the allowlist fails the step. This catches anything that slips past the CLI's own filtering.

See Runners for the details.

Deterministic checks

verify: is where quality is decided. Some checks that pay off:

  • caffeine scope <globs>: the diff stays inside the expected files.
  • Build and tests: cargo build -q && cargo test -q, npm test.
  • Format checks on what an agent produced: every item has a source URL, the JSON parses, a card keeps the HTML a parser expects.
  • A smoke test of the running app: start it, request the important routes, compare with the result before the change.

When the same correction comes up twice in your reviews, turn it into a check.

Trust

InputTrusted?
~/.caffeine (config, pipelines, prompts, checks)Yes: it is yours.
.caffeine.conf in the current folder or a dir: targetYes: you chose to run there.
.caffeine.conf in a git cloneNo, unless the target sets trust_project_conf: true.
File contents, web pages, tool results seen by an agentNo: the default rules tell agents to treat them as data.

A project file can change models, mcp, context and since_days, and narrow network. The hosts a step may reach come from your config's model roles and MCP servers, never the project's: a role it redefines (another runner, a network:, a base_url) or an MCP server it redefines (another url) adds no host. It can never change targets, guard, sandboxes, networks or claude_bin.

Runs that overlap

One run at a time per target and pipeline: a second one is refused while the first runs (a lock in ~/.caffeine/locks/, taken over if its process is gone). Different pipelines on the same target, or one pipeline on different targets, run side by side.

Pull requests and auto-merge

  • caffeine pr only commits in a fresh clone made by the run, on the run's own branch. It refuses to run anywhere else, so your checkout and your default branch are never committed to directly.
  • --auto-merge merges as soon as every earlier step and check passed. Only enable it on pipelines whose checks cover what matters, ideally including a runtime smoke test. A green build is not a working site.

What caffeine does not protect

  • run: steps and checks are your code. They run with your permissions, and the guard still checks their changes afterwards.
  • cmd agents follow their own CLI's permission system, not caffeine's allowlist. The guard and verify run after them, but anything they do outside the workspace (network, other folders) is not seen. Give their steps a sandbox: and a network: if you don't trust them.
  • Builds run project code. cargo build, npm install and friends execute scripts from the project and its dependencies. Allowing them on a repo means trusting that repo, unless they run in a sandbox, ideally with network: none once the dependencies are there.
  • A sandbox is only as tight as its engine. A container shares the host's kernel, and runs with --security-opt label=disable, so SELinux does not confine it (the price of mounting your folders without relabelling them); bwrap shows the host's /usr and /etc. full network is the engine's: under bwrap it is the host's own network namespace, so a step reaches services listening on localhost and abstract Unix sockets (a D-Bus session, an X server) as you would. Host lists can only be enforced on a Kubernetes cluster that runs Cilium, where only the listed names resolve and only their addresses can be reached. A NetworkPolicy does nothing on a cluster whose CNI ignores them (flannel, for one): caffeine cannot tell. Gates and check actions refuse to run in a sandbox: they need your home and credentials, so their steps stay on the host. So does caffeine pr, except as the last step of a kubernetes run (below).
  • A Kubernetes run checks itself in its pod. The guard, the snapshot, changes.diff and summary.json are made by the caffeine copied into the pod, where the steps ran: a step that takes over the pod can forge them. caffeine copies back only plain files, and the pod has no credentials to the cluster, but treat the result of a kubernetes run as you would its changes.
  • A pull request from a pod uses a token in a pod the agent had. Only the last step's caffeine pr gets the pr_env values: not the pod's environment, its Secret, an argument or a file. That step runs caffeine pr and nothing else (no other command in its run:, no verify:), so no command of the agent's clone (a package.json script, a Makefile) runs with the token. Before it runs, the pod's caffeine kills every process the earlier steps left (it is their subreaper, so a daemonized one is found too; one it cannot kill, another user's, refuses the pull request), and it is itself non-dumpable, so a step cannot read its memory, file descriptors or environment through /proc. What remains: the earlier steps wrote the clone, HOME and anything in the image the pod's user can write, and caffeine pr uses them with the token in its environment. caffeine runs its own copy of itself with the image's PATH (nothing under /caffeine, which the steps could write), turns off the clone's hooks and fsmonitor, replaces its credential helpers, keeps the token from git add and git commit, and pushes to the target's git: URL and points gh at it (--repo) whatever the clone's remotes say, but the rest of the clone's .git/config (url.<base>.insteadOf, http.proxy with http.sslVerify off, a custom CA) and of HOME (~/.gitconfig, gh's config) still steers git push and gh, and an image run as root lets a step replace git, gh or sh. A process of the pod's user that is still alive could read /proc/<pid>/environ of caffeine pr, which is why none is left. Use an image with a non-root user, and a fine-grained token limited to the repository (contents and pull requests), which expires.
  • In-place targets are changed in place. caffeine run in the current folder edits your files. Use a git repo, so that git diff and git checkout stay available, or a git target, which works on a throwaway clone.
  • caffeine never follows a step's symlinks. What it copies out of .agent/ (to the logs and the memory) skips symlinks, and what it writes in the logdir or the workspace replaces a symlink instead of writing through it: a step cannot aim a host read or write at your files.
  • A hard kill cleans nothing up. The first Ctrl-C (or SIGTERM) stops the run cleanly: the running step and everything it started are killed, the workspace is cleaned and the summary says interrupted. A second Ctrl-C, kill -9 or a crash exit at once: a clone left in ~/.caffeine/app/ is replaced by the next run, and a .agent/ left in a folder blocks the next run there until you delete it, on purpose, since caffeine never deletes a .agent/ it did not create.
  • claude.ai connectors reach your real accounts. With claude_connectors: true, list only the tools a step needs (read-only ones for proposing steps) and keep irreversible actions out of apply (see Inbox).

On this page