Containerized Agent-Development Environment Standards
Containerized Agent-Development Environment Standards
Section titled “Containerized Agent-Development Environment Standards”These standards govern how a project provides a sandboxed, reproducible development container for autonomous AI coding agents (Claude Code, Gemini CLI, Cursor, Google Antigravity, and similar). They build on the automation model in arch-02_automation_standards.md and the CI/CD pipeline rules in arch-08_ci_cd_pipeline_standards.md, and they inherit the P0–P2 severity model from ../security/sec-01_security_standards.md.
The governing principle: grant agents broad execution permissions, but only
inside a disposable container that cannot contaminate the host and cannot exfiltrate
data. “YOLO” autonomy is safe precisely because the blast radius is bounded — a
mounted workspace, a whitelisted network, and a git checkpoint to roll back to. An
agent running with --dangerously-skip-permissions directly on a developer’s
host is a P0 violation; the same agent inside a properly-scoped container is the
intended workflow.
A starter kit implementing these rules lives at
templates/containerized-dev/. It wires the
workflow — images, workspace volume, identity and secret injection, IDE
bootstraps — and ships the enforcing egress layer §4 requires: an internal: true
container network whose only way out is a deny-by-default proxy sidecar fed by the
generated allow-list. It still does not make a project compliant on its own:
the Docker socket mount is an explicit, documented opt-in, image builds run
outside the contained network, and the whitelists have to be adapted. Install the
kit into a consumer project with .standards/scripts/setup.sh --containerized
(opt-in; existing files are never overwritten, .env and .env.secret are
git-ignored), adapt the toolchain and whitelists, and treat §8 — in particular the
observed deny-path failure on your host — as the only evidence of compliance. The
kit’s README lists exactly which controls it enforces, how, and what remains
outside their reach.
1. Two Images, Two Purposes — Never One
Section titled “1. Two Images, Two Purposes — Never One”- Ship a development image (
Dockerfile.dev) and a production image (Dockerfile.prod) as separate build targets. They have opposite security postures and must never be conflated. - The dev image optimizes for agent capability: a full toolchain, a shell, package managers, and the AI CLIs. It is never deployed.
- The prod image optimizes for a minimal attack surface via multi-stage
builds — compile in a builder stage, copy only the runtime artifact into a
distroless or Alpine-minimal final stage. The final image MUST have no shell,
no package manager, no AI tooling, and run as a non-root user
[P0]. Anything an attacker could pivot through that is not required at runtime is a defect. - CI MUST build and scan the prod image; the dev image is a local convenience and SHOULD NOT be published to a public registry.
2. Non-Root Developer User with Scoped Sudo
Section titled “2. Non-Root Developer User with Scoped Sudo”- The dev container runs as a non-root user (e.g.
developer), created at build time with a stable, non-zero UID/GID. Running the agent asrootinside the container defeats the point of the sandbox and produces root-owned files on the host bind mount. - Passwordless
sudoinside the dev container is acceptable — it is a throwaway sandbox and agents need to install packages mid-task. Passwordless sudo in a prod image is a P0 violation. - Never mount the host Docker socket by default
[P1]./var/run/docker.sockgives whatever runs inside — including an agent with permissions skipped — root-equivalent control of the host daemon and a trivial escape path, which voids the containment this standard relies on. If a project genuinely needsdockerinside the sandbox, make the mount an explicit, commented opt-in with the trade-off documented beside it, and prefer a rootless Docker-in-Docker sidecar or a remote builder. - Match the container UID to the host user’s UID where the platform makes host ownership matter (Linux bind mounts), so files the agent writes are not root-owned on the host. Document the UID assumption next to the Dockerfile.
3. The Workspace Is a Volume, the Image Is Disposable
Section titled “3. The Workspace Is a Volume, the Image Is Disposable”- Mount the codebase into the container at a canonical absolute path —
/workspace— via a bind volume. This is the host reference checkout; editable work uses declared source overlays or a fresh clone in a container-owned volume at a documented path. The host checkout is read-only by default, with only explicitly declared source directories writable as narrow overlays. Never start with a writable checkout and enumerate protected files: new host consumers would be exposed. Container-owned volumes may hold editable clones and build output; they must never be mounted back into a host-side execution or configuration path. Nothing the agent needs to keep lives inside the image layer. - Treat the image as rebuildable at any time. A developer must be able to
docker compose build --no-cacheand lose nothing but caches. Persist only what is intentionally external: the mounted workspace, container-owned editable clones, and named volumes for language caches (~/.cache,node_modulesif not bind-mounted, Go module cache) to keep rebuilds fast. - Pin the base OS and every tool version. “Ubuntu 24.04 + Node LTS” is reproducible only if LTS resolves to a pinned major and the lockfiles are committed. A floating base tag means two developers get two different sandboxes.
4. Egress Control — the Dual-Layer Whitelist [P1]
Section titled “4. Egress Control — the Dual-Layer Whitelist [P1]”An autonomous agent with network access can exfiltrate a repository. Default-deny egress and allow only what the project needs.
- Deny by default. The container’s outbound traffic MUST be denied unless the
destination appears on an allow-list. A dev sandbox that can reach
malicious-site.comhas no containment. - Two layers, combined at setup time:
- a global allow-list shipped with the standards
(
network/global-whitelist.txt) covering the baseline every project needs — package registries, the AI provider APIs, the git host; - a project allow-list (
proxy/project-whitelist.txt) for project-specific destinations (a private registry, an internal API).
- a global allow-list shipped with the standards
(
setup-proxy.shreads both, concatenates and de-duplicates them, and generates the combined allow-list artifact that the enforcing layer consumes — an egress proxy’s allow rules or firewall rules. The combined list is a generated artifact; edit the source lists, never the generated output.- Environment variables are not enforcement.
HTTP_PROXY/HTTPS_PROXY(set in both upper and lower case, because tools disagree on which they read) only tell cooperative processes where to send traffic; anything that ignores or unsets them goes direct.NO_PROXY/no_proxyis a proxy bypass list for loopback and internal addresses — it is never the allow-list. Deny-by-default exists only when the container network cannot reach the internet except through a proxy that refuses unlisted destinations (internal: truenetwork + sidecar), or host firewall rules achieve the same. - Verify the deny path, not just the allow path. A whitelist that lets every
listed host through but silently also lets unlisted hosts through is worse than
none — it looks safe. The Definition of Done for any egress change is: a request
to an unlisted domain is blocked, proven by an actual failed request, not by
reading the config. Prove the second half too: a request that bypasses the
proxy variables (
curl --noproxy '*') MUST also fail, or the network — not the environment — is not the control. Make the check honest:curl --fail, since a plain-HTTP 403 otherwise exits 0 and the check passes on an open proxy. - Reference enforcement topology (what the starter kit ships):
- the dev container is attached only to an
internal: truenetwork, which has no route to the internet or the host LAN; - a proxy sidecar is attached to that network and to a second, non-internal
network, and is the only member with an internet route. It consumes the
generated allow-list and refuses everything else before dialling out
(deny by default), matching entries as whole hosts —
github.comMUST NOT matchgithub.com.evil.example— with an optional*.prefix for subdomains; - the sidecar fails closed and trusts nothing it is handed: it asserts its
own deny-by-default config at start (the config is baked into the image, not
mounted) and validates every allow-list entry against the same grammar
the generator uses — lowercase hostnames of two or more labels, optionally
*.-prefixed — so a missing, empty, hand-edited or stale allow-list (a bare*, any other glob,*.com, a URL) stops it from starting. The dev container waits for it to be healthy, so a broken allow-list halts the environment rather than opening it; - container writes, host executes: use the inverted mount model:
the whole host checkout at
/workspaceis read-only, including missing paths, vendored standards, submodule working trees and their.gitgitfiles. Only explicitly declared source directories may be writable overlays; no host-side step may read, execute or import configuration from those overlays. Host-consumed files include setup scripts, compose and all Dockerfiles,.env*,.gitignore,.git*, both global allow-list fallback trees (.standards/,coding_standards/),proxy/, agent/IDE/MCP configs,Makefileand package manifests. A deny-list of read-only mounts is not a substitute for a read-only root.initializeCommandmay run only scripts protected by that root, whose inputs are also protected. Never import workspace MCP commands into host settings: install host servers separately from reviewed, host-owned sources. A guard must reject a writable root or an unreviewed overlay, so adding a host consumer cannot silently expose it; - the engine must not forward external DNS from the internal network (Moby CVE-2024-29018 did, with a loopback host resolver): a forwarded lookup leaks data in the name without any connection. Require a patched engine and prove it with a failed lookup, not just a failed request;
- the sidecar publishes no host port — a reachable proxy with no client restriction is an open proxy for anything on the LAN;
setup-proxy.shlowercases every entry and rejects any that is not a hostname of two or more labels, so a URL, path, bare*or*.comin a source list can never widen the generated rules, and mixed case cannot silently fail to match a case-sensitive filter;- protocols without proxy variables are tunnelled, not exempted: git over SSH
uses a CONNECT
ProxyCommandthrough the sidecar, and the sidecar permits CONNECT only to the ports that need it (443, 22); sudoinside the container preserves the proxy variables (env_keep) so privileged package installs go through the sidecar rather than failing — this changes where traffic goes, never what the allow-list permits.
- the dev container is attached only to an
- Know what the proxy cannot see. It filters by destination host, not URL —
TLS is not inspected, so an allowed host is allowed for every path on it; prefer
exact hosts to wildcards. Image builds (
docker compose build) run on the Docker host network and are not filtered; keep build steps to pinned, reviewed sources (§3). Anything that reaches outside the internal network by other means — most notably a mounted Docker socket (§2) — bypasses the proxy entirely. - Comment lines (
#) and blank lines in the whitelist sources are ignored so the lists can be self-documenting.
5. Identity Injection Without Baking Secrets [P0]
Section titled “5. Identity Injection Without Baking Secrets [P0]”Agents need to push commits and call provider APIs, but credentials MUST NOT be baked into an image layer or committed.
- SSH agent forwarding, not copied keys. Forward the host’s
SSH_AUTH_SOCKinto the container for git operations. NeverCOPYa private key into an image — it persists in the layer history even if later deleted. - Git identity by mount. Bind-mount (read-only) or symlink the host
~/.gitconfigso commits carry the right author without duplicating config. - API keys via git-ignored env file.
init-workspace.shdetectsANTHROPIC_API_KEY/GOOGLE_API_KEY(and peers) in the host environment and writes them to a git-ignored.env.secret, which compose injects at runtime..env.secretMUST be in.gitignorebefore it is ever written; a committed key is a P0 incident. Prefer values passed at runtime over any value in a build arg — build args are visible in image history. - Keep the setup idempotent: re-running
init-workspace.shrefreshes identity and secrets without clobbering local edits, and skips cleanly when a variable is absent rather than writing an empty secret.
6. YOLO Permissions Are Earned by the Sandbox, Not Assumed
Section titled “6. YOLO Permissions Are Earned by the Sandbox, Not Assumed”Zero-friction autonomy is configured inside the container image only, and is paired with a rollback mechanism.
- Pre-configure the agents for unattended execution in the dev image: e.g. a
claudeshim that passes--dangerously-skip-permissionsand ageminishim that passes--yolo(Gemini CLI’s “auto-approve all tools” mode, also--approval-mode yolo), plus an auto terminal policy for IDE agents such as Antigravity. Use shims onPATH, not shell aliases: an alias only expands in an interactive shell, sodocker compose exec dev claude -p …, an IDE task or a script would still prompt. These settings MUST live in the container, never in a developer’s host dotfiles. - Checkpoint before autonomy. Agents MUST be instructed (via the assembled
agent config) to create a git checkpoint — a commit or a
git stash/wip/branch — before running a batch of unattended, destructive-capable commands, so any run is instantly recoverable. See ../process/proc-02_git_version_control_standards.md. - The combination is the control: broad permissions + bounded blast radius + one-command rollback. Remove any one leg and the “YOLO” posture becomes reckless.
7. IDE Integration Is Scripted and Optional
Section titled “7. IDE Integration Is Scripted and Optional”Every editor connects to the same container and the same /workspace so the
CLI agents and the human see one filesystem. Provide bootstrap scripts rather than
manual setup docs, and make each opt-in.
- VS Code Dev Containers: ship
.devcontainer/devcontainer.jsonpointing atdocker-compose.dev.ymlso “Reopen in Container” just works, with the project’s agent extensions declared. - Cursor: a root
.cursorrulesinstructing the agent to execute terminal commands inside the container and treat/workspaceas the absolute root. - Zed (headless remote): a bootstrap script that adds an SSH
Hostentry for the container’s forwarded port and installs the Zed remote server inside it. Zed connects over SSH, so this path needssshdin the dev image and a loopback-bound published port — both opt-in; the script MUST check for them and refuse to write aHostentry that cannot connect. - Google Antigravity: a bootstrap script that registers the container shell in the Agent Manager. Project MCP servers run inside the container; host MCP servers are installed separately from a reviewed source, never copied or merged from the workspace.
- Keep IDE bootstrap scripts non-destructive — append an SSH
Hostblock or MCP entry, detect and skip if already present, and never rewrite a user’s~/.ssh/configor global editor settings wholesale.
8. Definition of Done for a Container Change
Section titled “8. Definition of Done for a Container Change”A change to the dev-container setup is done only when:
docker compose uplaunches a functional dev environment and the agent CLIs run a trivial command (ls) through the container shell without permission prompts.- The egress proxy blocks a request to an unlisted domain — demonstrated by a failing request, per §4.
- At least one IDE path (Dev Containers or Cursor) connects and sees the same
/workspacethe CLI agents see. - The host-checkout root is read-only even for container
sudo; attempts to create or replace host setup, global allow-list, MCP and submodule.gitinputs fail. Every writable source overlay has an explicit host-consumer audit, and the boundary guard rejects unreviewed writable mounts. - No secret, private key, or API key appears in any committed file or image layer,
and
.env.secretis git-ignored.