Skip to main content

Runbook: enabling sandboxed code execution for an org, and the two kill levers (core#4633)

Sandboxed code execution covers the code_exec tool node and the sandboxed coder of the SDLC workflow (Stage 2, tracker #4630). It runs agent-produced code, so it is enabled per org, explicitly, by an operator. Rulings: HLD #2597 D1–D3 (founder, #4578 comment 6980541294). Design: ADR-0037 D8.

0. Where this may be done at all​

Dev only. Ruling D3 forbids enabling code execution on beta, prod or a customer install until the GKE PodExecutor is wired and SANDBOX_ENFORCE_RUNTIME=true passes the egress-escape smoke on runsc. Issue #4637 holds that gate (prod-enablement). On dev the sandbox runs runc-degraded with a loud warning. That is the only enabled target today.

Neither lever below needs a deploy, and each one is reversible in under a minute.

1. The enablement chain​

A sandboxed execution runs only if all of these hold. They are checked in this order. The first one that fails denies the run, before any container, clone or launcher call exists:

#ConditionWhere it is checkedRefusal text
1WF_CODE_EXEC_ENABLED=true on the processcmd/agent-orchestrator builds the code_exec provider only when the flag is on. The coder dispatch checks it first (sandbox.CheckEnablement).code_exec: disabled on this deployment (WF_CODE_EXEC_ENABLED is off) (fail-closed)
2The org has a code_exec_org_enablement row (migration 296)The code_exec provider (codeexec_invoker.go, before guardrails, the idempotency marker, the policy and the sandbox) and the coder dispatch (orchrt CoderDispatch)code_exec: org not enabled (fail-closed)
3The run's clearance is 4 or higher (ruling 5)The coder dispatch (RunScope.Clearance). For the code_exec node, the tool catalogue's floor applies at create time and the Governor applies it at session start.code_exec: run clearance is below the floor of 4 (fail-closed)

If the org row cannot be read (a DB error), the run is denied with code_exec: org enablement could not be checked (fail-closed). The cause is logged, never returned. A code_exec node retries that error. An absent row is a final refusal.

For the coder, all three steps currently run inside the CoderDispatch handler. That placement is interim. S3 (#4634) moves the clearance check into PreToolUse, beside the Governor, and amends ADR-0037 D8 to match.

There is no third flag. The process flag and the org row are the two kill levers of HLD #2597 §5.

2. Turn on the process flag (dev)​

The flag is one variable. It feeds both context-engine (the tool catalogue offers code_exec only when it is mounted, #2569) and agent-orchestrator. Both read it from docker-compose.dev.yml, with a default of false.

# in the live dev .env (never committed)
WF_CODE_EXEC_ENABLED=true
# recreate only the two readers
docker compose -f docker-compose.dev.yml up -d --no-deps context-engine agent-orchestrator

Check the orchestrator boot log: WR2-3 code_exec provider ENABLED — governed sandbox execution is live and code_exec_enabled=true.

3. Enable an org (lever 1, per org, live)​

Run this as the migration role on the target database. The runtime role (app_rw) can read the table but cannot write it or call the functions: migration 296 and dev/postgres/app-role.sql revoke those rights.

-- find the org
SELECT id, name FROM organizations WHERE name ILIKE '%<org name>%';

-- enable it: this records who and why, and seeds the org's `coder` resource tier
SELECT code_exec_enable_org('<org uuid>', '<your name>', '<issue / reason, e.g. core#4630 S5 acceptance>');

code_exec_enable_org writes two things:

  • the code_exec_org_enablement row. Re-running it updates enabled_by, enabled_at and note.
  • the org's coder tier in code_exec_resource_policy: CPU 2 cores, 4 GiB memory, 3600 s wall clock, 2 GiB disk, 512 pids, 1 MiB output. If the tier row already exists it is kept, so an operator's tuning survives a re-enable. To change the tier, UPDATE it under SET app.org_id.

A mistyped org id fails with a foreign-key error (code_exec_org_enablement_org_id_fkey), so the call never silently enables nobody. A blank operator name is refused by code_exec_org_enablement_enabled_by_check.

Verify:

SELECT org_id, enabled_by, enabled_at, note FROM code_exec_org_enablement;

4. The two kill levers​

Lever 1: one org, live, no restart.

SELECT code_exec_disable_org('<org uuid>'); -- true if a row was removed

The next code_exec node and the next coder dispatch for that org are refused with code_exec: org not enabled (fail-closed). Nothing already running is interrupted. A coder session that is already open runs until its own wall clock or budget ends it.

Lever 2: the whole deployment, one restart.

WF_CODE_EXEC_ENABLED=false # in the live .env
docker compose -f docker-compose.dev.yml up -d --no-deps context-engine agent-orchestrator

The provider is not built, the catalogue stops offering code_exec (#2569), and every coder dispatch is refused at step 1.

Emergency, every org, live. This is the HLD §5 allowlist lever. It needs no restart, and it breaks the runtime image resolution rather than the enablement:

UPDATE code_exec_runtime_allowlist SET enabled = false; -- undo: SET enabled = true

5. The coder runtime image and its pin​

The sandbox runs images/code-exec-coder, and only by the digest pinned in code_exec_runtime_allowlist (language coder). The image contains:

  • the Claude Code CLI, copied out of the same claude-agent-sdk wheel the agent worker locks (TestCoderImageCLIVersionMatchesWorkerPin)
  • git, Go, node with pnpm, and python with uv

Every package manager in the image is configured offline. The sandbox network has no route.

scripts/code-exec-coder-image.sh builds the image and checks the pin. CI publishes it in publish-images.yml, job code-exec-coder. Each image is published once per content tag ctx-<sha256(Dockerfile)[:16]> and never rebuilt over an existing tag. To change the image:

  1. Edit the Dockerfile on a branch. For a CLI bump, change the worker pin in the same PR.
  2. Dispatch Publish Images to GHCR on that branch with coder_image_only=true. The job publishes the new content tag, proves it (selftest: the CLI version with --network none, an offline go test, a read-only root, uid 65534), scans it with Trivy (CRITICAL, fixable), and prints the digest to pin.
  3. Pin that digest in a new migration: an INSERT of the new coder row and the removal of the old one. The migration notes must name the new content tag. Until they do, TestCoderPinTracksTheDockerfile fails: it follows the highest-numbered migration that pins the coder image, as verify-pin does. Never edit an applied migration.
  4. On main, the job's verify-pin step fails if the migrations do not pin the published digest.

Two consequences of running that job on main:

  • A newly disclosed fixable CRITICAL turns Publish Images to GHCR red on main. The job re-scans the existing image whenever one of its inputs changes, and those inputs include services/agent-worker/uv.lock and publish-images.yml, so an unrelated push can trigger it. That red is intended. The fix is owned by whoever owns the coder image, which for Stage 2 is the backend-sme author of the slice touching it, with the devops lane reviewing. The fix is a Dockerfile change plus a new pin through steps 1–3. It is never a .trivyignore entry without the security lane's review. While main is red, dev-deploy's workflow_run leg skips; the scheduled reconcile still runs.
  • The in-container selftest first runs in CI on the first main push after this lands. The bootstrap publish ran an earlier selftest revision, so until that push the current selftest has only been proven on the dev box. The tag already exists, so that push does not rebuild: it runs selftest, Trivy and verify-pin against the pinned digest. Read that run.

Local proof on the dev box, with your own tag and never touching the running stack:

bash scripts/code-exec-coder-image.sh build my/code-exec-coder:$(bash scripts/code-exec-coder-image.sh tag)
bash scripts/code-exec-coder-image.sh selftest my/code-exec-coder:<tag>

6. Known limits (owned by later slices)​

  • The docker launcher's /tmp is too small for Go. dockerlauncher.go mounts a 32 MiB noexec tmpfs at /tmp. Measured with this image on 2026-11-20: go test on a one-file package fails with no space left on device, because the Go build cache lives under /tmp and the test binaries execute from there. The coder launch (#4632 / #4634) has to back /tmp with the coder tier's disk and mount it exec. The selftest proves the image under a 256 MiB exec tmpfs.
  • The image holds toolchains, not dependencies. With GOPROXY=off and offline pnpm and uv, a repository whose tests need modules that are not in the image cannot build them in the sandbox. Either the workspace brings them, or a later image bakes them for a pinned pilot repository. The coder's inner loop is a smell test, and CI stays the gate (HLD #2597 §4).
  • runc on dev. runsc is operator action 6. Until it is installed, every sandbox run on dev is runc-degraded.