Skip to content

fix(sandbox): refuse docker-in-sandbox where admission forbids it - #619

Merged
pikann merged 3 commits into
Paca-AI:masterfrom
siedlegroup:fix/disable-docker-in-sandbox
Oct 21, 2026
Merged

pikann merged 3 commits into
Paca-AI:masterfrom
siedlegroup:fix/disable-docker-in-sandbox

Conversation

@kayahk

@kayahk kayahk commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Symptom

Creating an environment (or running an agent conversation) with docker_enabled on the Kubernetes sandbox backend never starts a Pod, and the failure does not name the real cause:

  • environment: Deployment.apps "paca-env-<id>" is invalid: spec.template.spec.containers[1].securityContext ... cannot set allowPrivilegeEscalation to false and privileged to true (a platform policy adding privilege-escalation hardening to the privileged sidecar — that one is fixed separately), and once past it, FailedCreate ... forbidden: violates PodSecurity "baseline:latest": privileged (container "dind" must not set securityContext.privileged=true) on a ReplicaSet retry loop, while the environment's PVC is already created and the row sits in creating until it times out.
  • conversation: the Job is created, its Pod never is.

Every Pod Security Admission level except privileged forbids a privileged container, so on a deployment whose sandbox namespace enforces Baseline — the level deploy/helm/README.md documents as the strictest the Kubernetes backend supports — a docker_enabled sandbox is un-runnable. Nothing in the API, the UI, or agent-runner knows that, so the operator gets minutes of retry loop and an error about a field pair rather than "this deployment cannot run docker".

Fix

Make the capability a first-class deployment setting, default-on so existing deployments are unchanged:

  • SANDBOX_DOCKER_IN_SANDBOX (default true) on agent-runner gates the Kubernetes backend's DinD sidecar. Start, CreateEnvironment and StartEnvironment refuse a docker_enabled sandbox before any API write, with an error that names the cause and the way out.
  • The same variable is read by the API and reported as docker_in_sandbox on GET /environments/config, which is already public and already the frontend's source for deployment-wide environment facts.
  • The environment-create dialog and both agent docker toggles are hidden when it is false, so the setting is not offered where it cannot work.

Refusing before the write also removes the leaked-PVC state: today a failed create leaves its PVC behind and the row at error with no backend_ref, so it can be neither started nor retried.

Verification

  • services/agent-runner: go build ./..., go vet ./..., full go test $(go list ./... | grep -v /test/e2e) pass.
  • services/api: same three gates pass.
  • New TestDockerInSandboxDisabled_RefusesBeforeSubmittingAnything covers all three entry points and asserts the refusal text plus zero Jobs/Deployments written.
  • Sabotage check: with the guard stubbed to return nil, the same test fails with
    Start error = sandbox/k8s: no pod matching selector "job-name=paca-sbx-…" got an IP after 1ms … want the docker-in-sandbox refusal (not a readiness failure) — i.e. it submits the workload again, exactly the reported behaviour.
  • Web: apps/web has no node_modules here, so no tsc -p and no component test. The four touched files parse under esbuild --loader:.tsx=tsx; biome@2 could not install its native CLI in this environment, and biome@1 flags import order on untouched files too, so it is not a usable signal.

Notes

  • Enforcement stays in agent-runner, which is the layer that knows the backend; the API field exists so the UI can hide the toggle, not as a second gate. An API-only caller that still sets docker_enabled gets the same refusal, immediately.
  • A deployment that wants docker-in-sandbox needs a sandbox namespace whose Pod Security Admission allows privileged Pods — a deliberate, node-level trust decision this change does not make for anyone.

Closes #618.

A docker_enabled sandbox gets a privileged docker:dind sidecar. On a
kubernetes backend whose sandbox namespace enforces any Pod Security
Standard — Baseline included — Pod Security Admission rejects that Pod
outright, so the workload can never run: for an environment the PVC is
created first and the Deployment then loops on FailedCreate (privileged),
for a conversation the Job's Pod is never created.

Make the capability explicit instead of discovering it from admission:

- agent-runner: SANDBOX_DOCKER_IN_SANDBOX (default true) gates the
  kubernetes backend's DinD sidecar, and Start/CreateEnvironment/
  StartEnvironment return an actionable error before any API write.
- api: the same variable is reported as docker_in_sandbox on
  GET /environments/config.
- web: the environment-create and agent docker toggles stay hidden when
  that is false.
The Kubernetes backend's DinD sidecar is privileged, so a sandbox namespace
enforcing Baseline cannot run a docker_enabled sandbox at all. Give the chart a
value for it and set SANDBOX_DOCKER_IN_SANDBOX on both agent-runner (which
enforces it) and api (which reports it on GET /environments/config).

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

apps/web/src/components/projects/environments/environment-create-dialog.tsx fails biome check, which is exactly the bun run lint step in web-pr-ci — CI will be red on this PR. Details inline. The rest of the change is sound: the agent-runner gate covers every workload-creating path before any write, and the API/helm/web wiring is consistent.

Reviewed changes — reviewed the deployment-level docker-in-sandbox gate end to end: the agent-runner refusal, the API config field and GET /environments/config, the helm wiring, the web toggle-hiding, and the new test.

  • agent-runner gate — SANDBOX_DOCKER_IN_SANDBOX (default true) flows to Manager.dockerInSandbox; requireDockerInSandboxAllowed refuses a docker_enabled sandbox in Start, CreateEnvironment, and StartEnvironment before any clientset write.
  • API surface — DockerInSandbox parsed with the same permissive fallback as agent-runner, exposed as docker_in_sandbox on GET /environments/config.
  • Helm — agentRunner.sandbox.dockerInSandbox wired into both the agent-runner and api Deployments; README and values.yaml updated.
  • Web — the environment-create dialog and both agent docker toggles are hidden when docker_in_sandbox === false, with an "older APIs" fallback that keeps them visible.
  • Test — TestDockerInSandboxDisabled_RefusesBeforeSubmittingAnything covers all three entry points and asserts zero Jobs/Deployments written.

ℹ️ The setting does not remediate already-running privileged Deployments

The flag only changes what agent-runner submits from now on. A docker-enabled environment created before the operator sets dockerInSandbox: false keeps its existing Deployment (still carrying the privileged dind sidecar), and the Kubernetes Deployment controller keeps recreating that Pod on eviction or node drain — with no agent-runner involvement. The new README text explains how to stop new docker sandboxes but does not tell the operator that pre-existing docker-enabled environments must be deleted for the namespace to be free of privileged Pods.

Technical details
# Non-retroactive docker-in-sandbox flag

## Affected sites
- `services/agent-runner/internal/sandbox/k8s/dind.go:82` — `dockerInSandbox` is read only here; nothing scales down or deletes an already-created Deployment.
- `services/agent-runner/internal/sandbox/k8s/environment.go:291` — `buildEnvironmentDeployment` sets `Replicas: 1`, so a pre-existing docker-enabled Deployment keeps a live privileged Pod independent of agent-runner.
- `deploy/helm/README.md:69-74` — added text covers refusal of new sandboxes only.

## Required outcome
- Documentation (README / `values.yaml` note) should state that existing docker-enabled environments must be deleted for a namespace to be free of privileged Pods after flipping the flag.

## Open questions for the human
- Should the change actively tear down/reconcile pre-existing privileged environment Deployments, or is documenting the manual cleanup sufficient?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread deploy/helm/paca/values.yaml Resolved
…ale values note

- environment-create-dialog: reindent the wrapped docker block (biome check
  formatting, i.e. web-pr-ci's lint step).
- agent-detail: keep the toggle visible when the agent already has
  docker_enabled, so an existing agent can still switch it off.
- values.yaml/README: the flag is not retroactive, and the sidecar note no
  longer claims there is nothing to configure.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — reviewed the 956983f..48b95b9 delta: the web docker-toggle conditions, the environment-create-dialog wrapper re-indent, and the helm docs rewrite. No Go changes in this range, and the three prior Pullfrog threads are all addressed.

  • Re-indented the docker-toggle block — environment-create-dialog.tsx's wrapped block now matches biome's indentation; biome check . passes over all 617 files in apps/web, so the web-pr-ci lint step is green.
  • Kept the agent docker toggle reachable — agent-detail.tsx now renders the switch when dockerInSandbox || dockerEnabled, so an agent already at docker_enabled: true can still turn docker off. create-agent-dialog.tsx is unchanged and safe here since new agents default to false.
  • Corrected the stale and incomplete docs — the values.yaml "nothing to configure here" note now points at dockerInSandbox, and both it and the README state the flag is not retroactive (a pre-existing docker-enabled environment keeps its privileged Pod until deleted).

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 71aade2 into Paca-AI:master Oct 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker_enabled sandboxes cannot run when the sandbox namespace enforces PodSecurity Baseline

2 participants