Skip to content

feat(sandbox): local Docker sandbox provider (#1695) - #1906

Merged
Glorf merged 4 commits into
mainfrom
feat/docker-sandbox-provider
Jul 9, 2026
Merged

Glorf merged 4 commits into
mainfrom
feat/docker-sandbox-provider

Conversation

@Glorf

@Glorf Glorf commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a built-in docker sandbox provider that runs each sandbox as a container on the local Docker daemon via the docker CLI — no OpenSandbox server or control plane required. It gives real container isolation out of the box on any machine with Docker, and plugs in behind the existing provider-neutral SandboxProvider protocol, so every agent built on nemo_gym.sandbox works with it unchanged. Part of the sandbox-providers epic (#1685).

Motivation

The existing providers need either a remote control plane (opensandbox) or a non-Docker local runtime (apptainer, common on HPC). There was no zero-setup path for the most common developer/CI environment — a machine with Docker. This provider closes that gap; provider choice is a one-line config swap.

Design

Mirrors the apptainer provider's shape — a single subprocess chokepoint, a readiness probe, and neutral status/error mapping. CLI-based, no new Python dependency.

flowchart LR
  Agent["Any agent"] --> API["nemo_gym.sandbox API"]
  API -- "create / exec / cp / close" --> P["DockerProvider"]
  P -- "docker run/exec/cp/rm" --> D[("local Docker daemon")]
  D --> C["sandbox container"]
Loading
  • One long-lived container per sandbox — docker run -d + a keep-alive PID; docker exec for commands, docker cp for files, docker rm -f for teardown. State persists across exec calls.
  • Config swap — registers under docker; the shipped docker.yaml binds the same sandbox name every provider config uses, so switching is a single +config_paths change (no agent edits).
  • --entrypoint override + --init — the keep-alive is injected via --entrypoint so images with their own ENTRYPOINT (e.g. SWE-bench) don't swallow it; --init (tini) reaps short-lived exec processes.
  • Auto-detected exec shell — uses bash when the image has it (needed for conda source, e.g. SWE-bench), falls back to sh; resolved once per sandbox after readiness. Overridable via exec_shell.
  • ttl_s self-destruct — when set (no custom entrypoint), the keep-alive sleeps for ttl_s and --rm removes the container on exit — a safety net for leaked/expired sandboxes.
  • Resource hard caps + isolation knobs — --cpus, --memory (+ a matching --memory-swap), --gpus <n>; opt-in network (incl. none), read_only, cap_drop, pids_limit, security_opt (e.g. no-new-privileges); never --privileged. Containers are labeled for orphan reaping, and --env values are redacted from error messages.
  • Per-sandbox provider_options — volumes (→ -v) and run_args.

Usage

ng_run "+config_paths=[$AGENT, nemo_gym/sandbox/providers/docker/configs/docker.yaml, $MODEL]"

or directly: Sandbox({"docker": {}}, spec).

Docs

Documented as a Fern provider page — fern/versions/latest/pages/infrastructure/sandbox/docker.mdx — a sibling of the Apptainer/OpenSandbox pages from #1717 with the same shape (setup / config / provider_options / resource mapping / lifecycle / isolation), plus a Docker card in the sandbox index. The in-repo README.md stays as the developer reference, matching the other providers.

Validation

  • 68 unit tests, 100% coverage of the provider module — hermetic (mock the CLI boundary) with skip-guarded real-daemon tests.
  • Real-daemon smoke: create / exec / seeded files / upload / download / status / close; ttl_s self-destruct verified live.
  • SWE-bench Verified (golden): gold patch applied and graded in-sandbox → reward 1.0.
  • SWE-bench Verified (agent): a hosted OpenAI-compatible model drove mini_swe_agent_2 end-to-end through the provider → resolved, reward 1.0.

Acceptance criteria (#1695)

  • Provider implementing SandboxProvider, registered in registry.py
  • YAML config + example, selectable via sandbox_provider
  • Passing tests, skip-guarded when Docker/daemon is absent
  • Docs — Fern provider page (sibling to the [codex] Add sandbox API docs guide #1717 sandbox pages) + repo README, covering setup + isolation/security
  • Validated end-to-end on a real runtime (rollouts collected)

Limitations

  • A command timeout returns a timeout result and leaves the reused sandbox running; the command's process is reaped with the container at close() (standard docker rm -f teardown).
  • Shares the host kernel — not an isolation boundary for untrusted code (use a VM/gVisor/Kata).

@Glorf
Glorf requested a review from a team as a code owner July 2, 2026 11:35
@copy-pr-bot

copy-pr-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Glorf
Glorf force-pushed the feat/docker-sandbox-provider branch from cbb3ea7 to 07ad621 Compare July 2, 2026 14:54
@ritaneves ritaneves linked an issue Jul 2, 2026 that may be closed by this pull request
5 tasks
@Glorf
Glorf requested review from ananthsub and hemildesai July 3, 2026 08:24
A built-in `docker` SandboxProvider that runs each sandbox as a container on
the local Docker daemon via the docker CLI -- no OpenSandbox server. It plugs
in behind the provider-neutral SandboxProvider protocol, so any agent on
nemo_gym.sandbox works with it by swapping one config path.

Highlights: one long-lived container per sandbox (docker run/exec/cp/rm);
bash auto-detected for conda images (e.g. SWE-bench), else sh; ttl_s
self-destruct (--rm + bounded keep-alive); hard resource caps
(--memory-swap == --memory); opt-in isolation knobs (network, cap_drop,
read_only, pids_limit, security_opt); --init + entrypoint override;
per-sandbox volumes/run_args; env values redacted in error messages.
Skip-guarded tests (no Docker required) + README with setup and security.

Signed-off-by: Michal Bien <[email protected]>
@Glorf
Glorf force-pushed the feat/docker-sandbox-provider branch from 07ad621 to 3f5d6f1 Compare July 3, 2026 08:42
@github-actions

github-actions Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

@Glorf

Glorf commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@kajalj22 could you help on the automation side? 🙏

@Glorf

Glorf commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@kajalj22

kajalj22 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

/claude review

@Glorf

Glorf commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@NVIDIA-NeMo/automation can I get your review 🙏

kajalj22
kajalj22 previously approved these changes Jul 8, 2026
@Glorf
Glorf dismissed stale reviews from kajalj22 and iguehring-nvidia via d240780 July 8, 2026 19:10
@kajalj22
kajalj22 self-requested a review July 8, 2026 20:14
@Glorf
Glorf enabled auto-merge (squash) July 9, 2026 07:30
@Glorf
Glorf merged commit 3dc011b into main Jul 9, 2026
16 checks passed
@Glorf
Glorf deleted the feat/docker-sandbox-provider branch July 9, 2026 07:32
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.

feat(sandbox): Local Docker sandbox provider

3 participants