Safety Guide
This guide covers good practices for using Cloche securely. The central concern is the Lethal Trifecta of LLM-powered agent usage: when a system simultaneously has (1) access to private data, (2) exposure to untrusted content, and (3) the ability to communicate externally, it becomes vulnerable to prompt injection attacks that can exfiltrate sensitive information. Cloche’s architecture is designed to let you break this trifecta, but only if you configure it correctly.
The Lethal Trifecta
Any system that combines all three of the following is at risk:
- Access to private data — The agent can read source code, credentials, API keys, internal documentation, or customer data.
- Exposure to untrusted content — The agent processes inputs that an attacker could influence: issue descriptions, pull request comments, dependency READMEs, web pages, or fetched API responses.
- Ability to communicate externally — The agent can make HTTP requests, send emails, push to remote repositories, or otherwise transmit data outside the local environment.
When all three are present, a prompt injection hidden in untrusted content can instruct the agent to exfiltrate private data through the external communication channel. The defense is to remove at least one leg of the trifecta.
Cloche helps by isolating agent work inside containers where you control filesystem access and network egress. But the host side of Cloche has no such isolation — host-side agent steps run with the daemon’s full OS privileges. The recommendations below focus on keeping host-side exposure minimal and container-side access locked down.
Container Isolation Model
Cloche containers get a copy of your project, not a bind mount. This is a deliberate security choice:
- Files in:
docker cpcopies the project into/workspace/. No bind mounts. Override files from.cloche/overrides/are applied on top (and kept out of the result branch unless the agent edits them)..git/is included so the agent can make commits. - Files out: On completion, the daemon extracts results via
docker cpinto a git worktree and commits to acloche/<run-id>branch. If the agent made commits inside the container, their messages are preserved in the squash commit. When no container commits exist, the commit message includes a file-change summary instead. - Deletions out: a tracked file missing from the container tree lands as a deletion; files
.clocheignorekept out of the container are restored, never deleted. If a result deletes more than 50 files and twice as many as it adds, extraction refuses to commit — that pattern usually means the container never had the full project (CLOCHE_EXTRACT_ALLOW_MASS_DELETE=1on the daemon overrides). - Auth files:
~/.claude/.credentials.jsonis copied into each container at/home/agent/.claude/for Claude Code session reuse. Autonomous (workflow) containers also get asettings.jsonreduced to its auth and environment keys — host hooks, model, permissions, and plugins are deliberately left behind so an agent step is driven by its prompt alone. Interactive consoles get the fullsettings.json,settings.local.json, and~/.claude.json. Copied (not bind-mounted) so each container gets its own isolated copy. - Network: Containers have network access (needed for API calls).
- Cleanup: Containers are removed after successful runs unless
--keep-containeris set. Failed runs always keep their container.
Your project directory is never modified by the container. You review the changes in a branch before merging.
Keep this model intact. Avoid using CLOCHE_EXTRA_MOUNTS to bind-mount sensitive host directories into containers. If you need additional files in the container, prefer the .cloche/overrides/ mechanism, which copies files at container start time.
Audit override files. Everything in .cloche/overrides/ is applied on top of /workspace/ in the container, including *.merge.* files, which are merged into project config files. Do not place credentials or sensitive configuration in this directory — it is checked into version control. Override files are left out of result branches unless the agent edits them, so an override never merges back into the project by itself.
Minimize Host-Side Agent Usage
Host workflows (those with a host { } block) run directly on the host machine. Agent steps in host workflows inherit the daemon’s permissions: full filesystem, full network, all environment variables.
Prefer container workflows for agent work. The workflow step type in host workflows dispatches work to an isolated container. Use it:
workflow "main" {
host {}
step prepare-prompt {
run = ".cloche/scripts/prepare-prompt.sh"
results = [success, fail]
}
step develop {
workflow_name = "develop"
results = [success, fail]
}
prepare-prompt:success -> develop
prepare-prompt:fail -> abort
develop:success -> done
develop:fail -> abort
}
In this pattern, the host workflow uses a script step (deterministic, no LLM) to prepare the prompt and a workflow step to dispatch it to a container. No agent step runs on the host.
If you must use host-side agent steps, limit what the agent can access:
- Run the daemon under a dedicated service account with restricted filesystem permissions rather than your personal user account.
- Avoid setting broad environment variables (cloud credentials, database URLs) in the daemon’s environment. Only export what is strictly needed.
- Keep host workflows simple — use them for orchestration (scripts and workflow dispatch), not for direct agent work.
Network Allowlisting
Containers should have the minimum network access needed for their task. The workflow DSL accepts a network_allow list in the container {} block to declare intended egress restrictions:
workflow "develop" {
container {
image = "my-project:latest"
network_allow = ["api.anthropic.com", "github.com"]
}
step implement {
prompt = file(".cloche/prompts/implement.md")
results = [success, fail]
}
implement:success -> done
implement:fail -> abort
}
Note:
network_allowis currently parsed by the DSL but not enforced at runtime — containers run with unrestricted network access. Until enforcement is implemented, use the Docker-level controls described below to actually restrict egress. Declaringnetwork_allowin your workflow is still recommended as documentation of intent and to be ready when enforcement lands.Exception: the locked-down DRA profile (
container { profile = "dra" }) does enforce its allowlist, through an egress sidecar on a Docker--internalnetwork. See Locked-down DRA containers.
A good allowlist includes only:
- The AI provider API endpoint (e.g.
api.anthropic.com) - Your git remote for pushing results (e.g.
github.com) - Language-specific package registries only if the workflow installs dependencies
Everything else should be excluded unless the task specifically requires it. The agent may be less capable without web access, but the security tradeoff is worth it for tasks involving sensitive code.
Docker Network Isolation
Since network_allow is not yet enforced, Docker-level network restrictions are currently the primary mechanism for limiting container egress:
Drop all network by default. If your workflow does not need any network (e.g. pure code editing with tests), bake all dependencies into the image at build time:
# In your .cloche/Dockerfile
FROM cloche-base:latest
COPY requirements.txt .
RUN pip install -r requirements.txt
When all dependencies are in the image, the container needs no outbound access except for the AI provider API.
Restrict DNS resolution. Containers use Docker’s embedded DNS by default. For tighter control, specify DNS servers that only resolve your allowlisted domains, or use a DNS-based firewall.
Avoid --privileged and --cap-add. Cloche containers do not need elevated capabilities. The base image runs as an unprivileged agent user. Never run Cloche containers with --privileged or add capabilities like NET_ADMIN unless you have a specific, justified need.
Credential Handling
API keys. The ANTHROPIC_API_KEY environment variable is automatically passed into containers. Other environment variables must be explicitly passed via CLOCHE_EXTRA_ENV. Only pass what the agent needs.
Claude credentials. Cloche copies ~/.claude/.credentials.json into containers for agent authentication. Autonomous runs also receive a settings.json reduced to its auth/env keys (env, apiKeyHelper, forceLoginMethod, forceLoginOrgUUID, awsAuthRefresh, awsCredentialExport, otelHeadersHelper); host hooks, permissions, model, and plugin settings are not forwarded. Interactive containers get the full settings.json, settings.local.json, and ~/.claude.json. Files are copied (not mounted) so concurrent runs do not conflict. Be aware that these files are present in the container filesystem during the run.
Do not bake secrets into Docker images. Use environment variables or runtime injection rather than embedding API keys, tokens, or passwords in your Dockerfile or .cloche/overrides/.
# Good: pass at runtime
CLOCHE_EXTRA_ENV=DATABASE_URL=postgres://... cloche run develop
# Bad: in Dockerfile
# ENV DATABASE_URL=postgres://...
Signal Intake Token
The web console’s HTTP listener has no authentication of its own: anyone who can reach the port can stop, delete, and start runs. Bind it to loopback (http = "127.0.0.1:8080") unless you trust the network. The exceptions carry their own credential: signals and tasks/create|update (below), /mcp (per run), and the DRA API (per wake-up).
POST /api/projects/{name}/signals (see Feedback Signals) requires a per-project bearer token. A signal can create a tracker task, and a task spends budget, so anyone who can post one can direct your spend — and, through the task text, steer the agent that works on it.
- The token is generated on first use and stored in
~/.config/cloche/signal-tokens/with mode0600. Treat it like a password: keep it in your sources’ secret stores, not in repos, Dockerfiles, or.cloche/overrides/. cloche signals tokenshows it;cloche signals token --rotatereplaces it immediately. Rotate if it leaks, or when someone who had it leaves.- An unknown project and a wrong token get the same
401, so project names can’t be probed. - The token travels in a header over plain HTTP unless you terminate TLS in front of the console. Don’t expose the listener to untrusted networks without that.
- Signal text (
title,evidence) is untrusted input that becomes a task body. The default workflow copies it unchanged; apply the Prompt Hygiene advice below before feeding it to an agent.
Prompt Hygiene
The content of prompts is the primary vector for injection attacks. Untrusted content that reaches an agent’s prompt can instruct it to take unintended actions.
Separate trusted and untrusted content. Prompt templates in .cloche/prompts/ are trusted — you write and review them. User requests (task descriptions, issue bodies) are untrusted — they come from external sources. Cloche’s prompt assembly concatenates these, so the agent sees both. Keep the trusted template’s instructions clear and explicit to reduce the chance of injection overriding them.
Validate external inputs in script steps. Use host-side script steps to sanitize or filter task descriptions before they reach an agent step. For example, .cloche/scripts/prepare-prompt.sh can strip HTML, limit length, or reject suspicious patterns, then write the cleaned text to the shared run folder and publish its path with cloche set task_prompt_path <file> (or store a small value directly in the KV store). The agent’s prompt template then pulls it in with {{@ $task_prompt_path }} or {{ $prev_output }}, so only content that passed through your script reaches the agent. See Communicating Between Steps for the mechanics.
Treat template directives as injection surfaces. Prompt templates can pull content in at assembly time: {{ $prev_output }} inserts the preceding step’s captured stdout, {{! cmd }} inserts a shell command’s output, and {{@ path }} inserts a file verbatim. If that content originates from untrusted sources — test output that echoes user-supplied data, fetched issue bodies, files a previous agent step wrote — it lands in the prompt unfiltered. Only pull in what the step needs, and prefer sanitized intermediates produced by a script step over raw upstream output.
Review Before Merge
Cloche extracts results to git branches, not directly to your main branch. Always review the agent’s changes before merging:
- Check for unexpected file modifications outside the task scope.
- Look for new dependencies, network calls, or credential usage that the task did not require.
- Verify that no files were added that could serve as persistence mechanisms (cron jobs, git hooks, CI config changes).
This review step is your final safeguard. Automated agents are powerful but not infallible — treat their output with the same scrutiny you would give any external contribution.
Locked-down DRA containers
A DRA is a long-lived agent, the riskiest kind, so its wake-up runs under tighter limits than a workflow run:
- Its own image (
cloche-dra): no compilers,make,git, tracker CLI, push credentials, or tracker data. - Read-only project. Everything under
/workspaceis root-owned and not writable by the agent user, except the DRA’s ownnotes.md. - Enforced network allowlist. The container joins a Docker
--internalnetwork with no route out. An egress sidecar relays only the model API and the daemon and Saga ports on the host. No--privileged, no extra capabilities,no-new-privileges. CLOCHE_EXTRA_MOUNTSandCLOCHE_EXTRA_ENVare not applied to these containers.- Fails closed. If any lock-down step fails, the container exits without starting the agent and the run fails.
Summary
| Risk | Mitigation |
|---|---|
| Host-side agent has full access | Use container workflows for agent steps; keep host workflows to scripts and dispatch |
| Unrestricted network in container | Declare network_allow; enforce with Docker-level network controls until runtime enforcement lands |
| Sensitive files in container | Rely on copy-based isolation; avoid bind mounts; audit overrides |
| Credentials leaking | Pass via env vars at runtime, not in images or overrides |
| Long-lived DRA agent | container { profile = "dra" }: own image, read-only project, enforced network allowlist |
| Console listener has no auth | Bind to loopback; terminate TLS in front of it before exposing it |
| Signal endpoint abuse | Per-project bearer token (cloche signals token --rotate); keep the listener off untrusted networks |
| Prompt injection | Sanitize untrusted inputs in script steps; keep prompt templates explicit |
| Malicious agent output | Review branches before merging; check for unexpected changes |