Skip to content

fix(sandbox): harden sandbox containers against privilege escalation#355

Open
manusjs wants to merge 1 commit into
vxcontrol:mainfrom
manusjs:fix/sandbox-no-new-privileges
Open

fix(sandbox): harden sandbox containers against privilege escalation#355
manusjs wants to merge 1 commit into
vxcontrol:mainfrom
manusjs:fix/sandbox-no-new-privileges

Conversation

@manusjs

@manusjs manusjs commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Four targeted container hardening changes for issue #337.

Important clarification (flagged by code review): no-new-privileges alone does not close the Docker socket escape vector — an attacker with socket access can ask the host daemon to launch a privileged container regardless of this flag. The changes here are genuine defense-in-depth, but the definitive fix for #337 remains DOCKER_INSIDE=false or fronting the socket with a least-privilege proxy. Issue #337 should stay open until that is addressed.

Changes

backend/pkg/docker/client.go — RunContainer hardening

  • no-new-privileges:true: prevents setuid/setgid and file-capability escalation inside the container
  • PidsLimit=2048: fork-bomb / resource exhaustion guard
  • Startup warning: logrus.Warn when DOCKER_INSIDE=true so operators see the socket-escape risk at boot
  • Comment corrected: no longer implies no-new-privileges mitigates the [Bug]: PentAGI Container Escape via Prompt Injection #337 socket escape (it doesn't)

backend/pkg/tools/tools.go — CapDrop ALL

Drop all Linux capabilities, add back only NET_RAW + optionally NET_ADMIN. Removes ~14 unnecessary caps (SYS_CHROOT, AUDIT_WRITE, MKNOD, etc.) from the default Docker set.

.env.example

  • Flip DOCKER_INSIDE default from true → false (aligns with config.go envDefault:"false")
  • Expand comment with socket-escape risk, DinD guidance, docker-socket-proxy link

What is NOT addressed (why #337 stays open)

The root cause — a process in the sandbox can POST to the Docker socket to launch a privileged container with the host filesystem mounted — is not addressed by these changes. Definitive mitigations are: DOCKER_INSIDE=false, a socket proxy, or rootless/sysbox DinD. This PR does the hardening safe to ship immediately while that architectural question is resolved.

Testing

  • go build ./pkg/docker/... ./pkg/tools/... — clean
  • go test ./pkg/docker/... ./pkg/tools/... — all pass

@manusjs manusjs force-pushed the fix/sandbox-no-new-privileges branch from a7138f7 to a924213 Compare June 24, 2026 16:17
@manusjs manusjs changed the title fix(sandbox): add no-new-privileges security option to all sandbox containers fix(sandbox): harden sandbox containers against privilege escalation Jun 24, 2026
@manusjs manusjs force-pushed the fix/sandbox-no-new-privileges branch from a924213 to 3c034c9 Compare June 24, 2026 17:37
Address the container escape risk reported in issue vxcontrol#337 (Docker socket
bind-mount when DOCKER_INSIDE=true).

Changes:

backend/pkg/docker/client.go — RunContainer hardening
  • Add `no-new-privileges:true` to SecurityOpt on every sandbox container.
    Prevents setuid/setgid and file-capability escalation inside the sandbox.
  • Add PidsLimit=2048 as a cheap fork-bomb / resource exhaustion guard.
  • Add startup warning (logrus.Warn) when DOCKER_INSIDE=true so operators
    see the socket-escape risk at boot rather than only in documentation.
  • Correct the comment to not imply the socket-escape vector is mitigated
    by no-new-privileges alone (it is not; the real fix is DOCKER_INSIDE=false
    or a least-privilege socket proxy).

backend/pkg/tools/tools.go — CapDrop ALL on primary terminal container
  • Drop all Linux capabilities then add back only NET_RAW (always) and
    NET_ADMIN (when DOCKER_NET_ADMIN=true). Removes ~14 unnecessary caps
    from the default Docker set (e.g. SYS_CHROOT, AUDIT_WRITE, MKNOD) that
    pentest tools should not need and that could be abused in an escape chain.

.env.example
  • Flip DOCKER_INSIDE default to false (aligned with config.go envDefault).
    The previous example was contradicting the code default.
  • Expand the DOCKER_INSIDE comment: explains socket-escape risk, DinD
    guidance, and links to docker-socket-proxy as a least-privilege alternative.

Note: DOCKER_INSIDE=false is the safest configuration; operators who need
DinD should consider fronting /var/run/docker.sock with a proxy rather than
mounting it directly.
@manusjs manusjs force-pushed the fix/sandbox-no-new-privileges branch from 3c034c9 to a50ba4c Compare June 24, 2026 17:46
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.

1 participant