Skip to content

feat(runtime): operator sandbox runtimes (gVisor, Sysbox) on Docker/Podman profiles - #5773

Closed
miller79 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
miller79:feat/oci-runtime-profile
Closed

miller79 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
miller79:feat/oci-runtime-profile

Conversation

@miller79

Copy link
Copy Markdown
Contributor

Refs miller79#37 (filed on our fork; scope agreed there with @ptone). Design note: miller79#37 (comment)

Draft: opened alongside the design note so the code can be read with it. Open questions are listed there; I'll adjust the shape before marking it ready.

  • Tests pass (targeted; see below)
  • Appropriate changes to documentation are included in the PR

What

Operator-declared sandbox runtimes for Docker and Podman, the counterpart of Kubernetes runtimeClassName. A profile in the Runtime Broker's global settings can declare:

profiles:
  build:
    runtime: docker
    sandbox_runtime:
      name: runsc-dind        # engine runtime name, passed as --runtime
      kind: gvisor            # gvisor | sysbox
      docker_storage_size: 6g # gvisor only

With the experiment agent_policy.sandbox_runtime on, agents started under that profile run with --runtime <name>, so they can run their own container engine (Testcontainers, image builds) without the host's engine and without --privileged.

Behaviour

  • Kind decides the flags. gvisor adds --cap-add ALL, --security-opt seccomp=unconfined and --tmpfs /var/lib/docker:rw,exec,size=<n>, and keeps CAP_NET_RAW. These are what Docker inside gVisor needs; they are confined to gVisor's user-space kernel and are only ever added together with the runtime. sysbox adds only --runtime.
  • Operator-only. Read from the global settings file only (config.LoadProfileSandboxRuntime). An invalid block refuses the start, and runc/crun names are refused.
  • Networking. gVisor agents always use bridge networking (gVisor can't share the host's network stack). SCION_FORCE_HOST_NETWORK with a gVisor profile is refused.
  • Fail open, safely. With the experiment off, or on a runtime other than Docker or Podman, the block is ignored with a warning and the agent starts on the default runtime.

Changes

  • pkg/config: V1ProfileConfig.SandboxRuntime, V1SandboxRuntime with Validate, and LoadProfileSandboxRuntime. Root schema and Hub profiles section schema (shape only).
  • pkg/runtime: RunConfig.Sandbox and appendSandboxRuntimeArgs, called by the Docker and Podman runtimes. The CAP_NET_RAW drop is skipped under gVisor.
  • pkg/agent: resolveStartSandboxRuntime, resolved before the host-networking decision.
  • pkg/experiments, pkg/hub: experiment agent_policy.sandbox_runtime (server, alpha, off), forwarded to brokers and classified deny in the test-admin policy.
  • Docs: experiments reference and the profiles table in orchestrator settings.

Tests

  • New: TestSandboxRuntimeValidate, TestLoadProfileSandboxRuntime* (pkg/config), TestAppendSandboxRuntimeArgs and TestBuildCommonRunArgs_NetRawDropKeptExceptUnderGVisor (pkg/runtime).
  • go test ./pkg/config/... ./pkg/runtime/ ./pkg/experiments/ pass. go vet of pkg/agent, pkg/runtime, pkg/config and pkg/experiments is clean, and gofmt is clean. node hack/check-docs-links.mjs reports 0 violations.
  • Not run locally: the pkg/hub test suite (it needs more memory than my machine has; CI will run it) and npm run build for the docs site.
  • End to end on a workstation hub (Docker 29, gVisor release-20261123, ptrace platform because of WSL): a claude agent on a build profile ran under gVisor on bridge networking, and as the scion user a testcontainers-go Redis test passed through the inner engine (mapped port, Ryuk). A --privileged inner container mounting / saw only the sandbox. With the experiment off, the agent started on runc with CAP_NET_RAW dropped.

🤖 Generated with Claude Code

Prototype for #37 (broker-level OCI runtime). A profile in
the broker's global settings can declare

  sandbox_runtime: {name: runsc-dind, kind: gvisor, docker_storage_size: 6g}

and, with the agent_policy.sandbox_runtime experiment on, agents started
under that profile run with `--runtime <name>`. For kind gvisor Scion also
adds the flags Docker-inside-gVisor needs (--cap-add ALL,
seccomp=unconfined, an executable /var/lib/docker tmpfs) and keeps
CAP_NET_RAW; those flags are confined to gVisor's user-space kernel and are
only ever added together with the sandbox runtime. kind sysbox adds only
--runtime.

- Read from the global settings file only (LoadProfileSandboxRuntime); an
  invalid block refuses the start; runc/crun names are refused.
- gVisor agents always use bridge networking (gVisor cannot share the host
  network stack); SCION_FORCE_HOST_NETWORK with gVisor is refused.
- Experiment off, or a non-Docker/Podman runtime: the block is ignored with
  a warning and the agent starts on the default runtime.

Verified on a local workstation hub (WSL, gVisor release-20261123 on the
ptrace platform): a claude agent on a build profile ran an inner Docker
engine and a testcontainers-go Redis test (Ryuk, mapped port) as the scion
user; a privileged inner container mounting / saw only the sandbox.
@miller79

Copy link
Copy Markdown
Contributor Author

Opened here by mistake; it was meant for our fork. Closing.

@miller79 miller79 closed this Nov 28, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces support for sandboxing OCI runtimes (such as gVisor and Sysbox) on Docker and Podman profiles, gated by the new agent_policy.sandbox_runtime experiment. It adds configuration schemas, validation logic, and runtime argument generation to run agents with restricted privileges and inner container engines. The review feedback highlights that the regular expression used to validate the tmpfs storage size for gVisor is overly restrictive, as it limits digits to six and only accepts lowercase suffixes. It is recommended to update the regex to be case-insensitive and support arbitrary digit lengths, along with adding corresponding test cases.

const DefaultSandboxDockerStorageSize = "6g"

var (
sandboxRuntimeNameRE = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$`)

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.

medium

The regular expression for validating the tmpfs storage size (sandboxTmpfsSizeRE) is overly restrictive. It only accepts lowercase suffixes (k, m, g), whereas standard size suffixes in Docker/Podman and tmpfs mounts are case-insensitive and commonly written in uppercase (e.g., 6G, 4096M). Additionally, it arbitrarily limits the number of digits to 6, which restricts sizes specified in smaller units (for example, 1048576k for 1GB would fail validation because it has 7 digits). Making the regex case-insensitive and removing the arbitrary digit limit makes it more robust and user-friendly.

\tsandboxTmpfsSizeRE   = regexp.MustCompile(\"(?i)^[1-9][0-9]*[kmg]$\")

wantErr string
}{
{"gvisor ok", V1SandboxRuntime{Name: "runsc-dind", Kind: "gvisor"}, ""},
{"gvisor size ok", V1SandboxRuntime{Name: "runsc", Kind: "gvisor", DockerStorageSize: "4096m"}, ""},

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.

medium

Add test cases to verify that uppercase suffixes (like 4G or 512M) are successfully validated, and that larger digit counts are also allowed.

\t\t{\"gvisor size ok\", V1SandboxRuntime{Name: \"runsc\", Kind: \"gvisor\", DockerStorageSize: \"4096m\"}, \"\"},\n\t\t{\"gvisor size uppercase ok\", V1SandboxRuntime{Name: \"runsc\", Kind: \"gvisor\", DockerStorageSize: \"4G\"}, \"\"},\n\t\t{\"gvisor size large digits ok\", V1SandboxRuntime{Name: \"runsc\", Kind: \"gvisor\", DockerStorageSize: \"1048576k\"}, \"\"},

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