Skip to content

GPUs in the sandbox (environment.gpu); ASPIRE's simulator confined with them - #93

Merged
haizhongzheng merged 2 commits into
mainfrom
sandbox-gpu
Nov 10, 2026
Merged

haizhongzheng merged 2 commits into
mainfrom
sandbox-gpu

Conversation

@haizhongzheng

@haizhongzheng haizhongzheng commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Change

GPUs in the sandbox. hermit's bubblewrap sandbox mounts a minimal /dev, so a sandboxed process had no GPU: CUDA found no device, and EGL fell back to Mesa's software renderer. Anything that needs a GPU therefore had to run outside the sandbox.

environment.gpu: [N, ...] (in code, Sandbox(gpu=[...])) shows the named NVIDIA GPUs and no other GPU's device:

  • Which GPUs: N is the N of /dev/nvidia<N>, a GPU's Minor Number in nvidia-smi -q.
  • Devices: each named GPU's /dev/nvidiaN, the driver's nvidiactl, and, when present, nvidia-uvm, nvidia-modeset and nvidia-caps (MIG).
  • Read-only from /sys: /sys/devices, /sys/bus/pci, /sys/module/nvidia and /sys/module/nvidia_uvm. CUDA and EGL read these to find a GPU. I measured them on an L40 host: without /sys/devices and /sys/module/nvidia, EGL falls back to llvmpipe; without /sys/bus/pci, CUDA finds no device. These entries describe every PCI device, the other GPUs included: that is information, not access to their devices.
  • Numbering: inside the sandbox the shown GPUs count from 0.
  • Errors: a GPU the machine lacks fails the call, and environment.image together with environment.gpu is refused.
  • Default: off, so behavior is unchanged unless a config sets it. Where nothing is confined (sandbox.enabled: false, runner: host, or best_effort without bubblewrap), every GPU is there, as everything else is.

The setting reaches the task sandbox, its tool sandbox, and its judge's sandbox (by dataclasses.replace). Documented in docs/guides/sandbox.md (item 9 under "How one sandbox is built"), docs/reference/config-fields.md, docs/developer/sandbox-design.md and hermit/defaults.yaml.

ASPIRE's simulator, confined (examples/aspire_robosuite). This closes the open item from #74. The actor's programs run inside cap-harness on the host, and ASPIRE's _ProgramValidator can be bypassed: attribute traversal inside a format string reaches os. A program could therefore read and write host files (other sessions' workspaces, the judge's Stage 2 runs) and run held-out seeds itself. Now every cap-harness and validator process runs in a hermit Sandbox of its own (utils/agent/sim.py: confine). That covers the simulator service's runs, the judge's sim.Engine, and the direct actor's.

What that sandbox allows:

  • Reads: ASPIRE's checkout, except examples/ (worked solutions), .claude/, .agents/, .codex/, tests/, outputs/ (its CLI's runs) and .git (the history holds them all).
  • Writes: only the run's own output. Run storage inside the checkout is refused, both in confine and in launch.sh.
  • Network: only the providers. That is ports 8114/8115/8116/8118 plus any CAP_HARNESS_*_URL port; a provider on another host is reached through an AllowlistProxy for that host only.
  • GPUs: the ones ASPIRE_SIM_GPU names. launch.sh passes them to the service and exports them for the judge; with none, rendering falls back to Mesa's software renderer. The host's CUDA_VISIBLE_DEVICES is not passed in, because inside the sandbox the GPUs count from 0.
  • HOME: each run gets a HOME of its own, removed after it, so caches do not land in the delivered output.
  • Start checks and records: the service refuses to start without bubblewrap, or with a GPU the machine lacks. Each confined run leaves a sandbox record under $ASPIRE_OUT/sim-service/sandbox/ (the service's runs) or $ASPIRE_OUT/sandbox/ (the judge's).

Supporting details:

  • Venv: ASPIRE's venv interpreter is executed by its own name, so it keeps its venv; the sandbox would otherwise run a command by its real path.
  • Hand-extracted EGL driver: shown file by file, with its library resolved the way GLVND resolves it. Other paths can be granted explicitly with ASPIRE_SIM_READ.
  • Host reads of the output: the host reads a run's output only after the process has ended. It first repairs the directory modes and removes links, pipes and devices, and it only reads a run_dir that lies inside the run.
  • Delivery: the service makes the run's own directory read-only to the run and refuses a replaced output. A session's program directory is passed per call, never as a trusted grant (a program could be named pyvenv.cfg).

The README's "actor's rules" section documents this, including the one thing it cannot do. A program that escapes the validator still runs in cap-harness's own process, so it could write its own run's outcome. Its score is not trustworthy, but it can affect nothing else.

Validation

  • CI: passed on a51bf6d (1327 passed, 69 skipped). This description is for the head with the audit fixes, 528b024.
  • Related tests: python -m pytest tests/core/test_sandbox.py tests/core/test_isolate.py tests/core/test_session_sandbox.py tests/core/test_sandboxed_evolvers.py tests/methods/aspire: 183 passed, and 3 skipped (existing --integration tests). Run as if bubblewrap were missing, the ASPIRE group gives 23 passed and 9 skipped, with a reason. This was on lovelace, which has 10× L40 and bubblewrap 0.x. The CI runner (Ubuntu 22.04) has a working bubblewrap: the last CI logs show no bubblewrap skips, so the ASPIRE tests run confined there. The real-GPU test skips without a GPU.
  • GPU in a sandbox, measured here:
    • With Sandbox(gpu=[8]), CUDA reports 1 device, and its UUID is GPU 8's per nvidia-smi -q -x. A matmul runs, and MuJoCo's EGL renderer is NVIDIA L40.
    • Without gpu, CUDA finds no device and EGL renders with llvmpipe.
    • The same holds through ASPIRE's confine with its default render environment (MUJOCO_EGL_DEVICE_ID=0), with a host CUDA_VISIBLE_DEVICES=3 (stripped), and with an inherited NVIDIA-only ICD selection: gpu=[8] renders on the L40, no GPU on llvmpipe.
  • Venvs: cap-harness and the validator ran in confine from real venvs (python -m venv) built on two different bases, hermit's Python 3.12 and a uv Python 3.13, and kept their venv packages.
  • Not verified:
    • A real ASPIRE checkout in confine. It may read paths outside the checkout this setup does not show (its uv cache, model caches; HOME is now a fresh directory per run); ASPIRE_SIM_READ grants them. Not verified either: Robosuite's check of MUJOCO_EGL_DEVICE_ID against CUDA_VISIBLE_DEVICES, and the RAM a run's temporary files take on the tmpfs /tmp.
    • A MIG host, a host whose /dev/nvidia-uvm does not exist yet, an AMD GPU (not supported: NVIDIA only), and a container.

Review

  • Tests and documentation cover the affected behavior, where applicable.
    • Tests: tests/core/test_sandbox.py and tests/methods/aspire/test_aspire.py.
    • Docs: listed under Change.
  • Commands, defaults, and public interfaces are consistent.
    • New: environment.gpu (default []), Sandbox(gpu=), and ASPIRE's ASPIRE_SIM_GPU, ASPIRE_SIM_READ, sim_service.py --gpu.
    • In hermit, nothing changes unless environment.gpu is set.
    • In ASPIRE's example, these change regardless:
      • the simulator always runs confined, so it needs bubblewrap;
      • its HOME is a fresh directory per run, and the host's CUDA_VISIBLE_DEVICES is not passed in;
      • sim.Engine.run's log moved from out/run-batch.log to <out>.run-batch.log beside it;
      • its tests need bubblewrap (they skip without it).
        The README says so.
  • Shared logs and examples contain no credentials or private data.
  • Documentation-only: not applicable.
  • Core changes.
    • hermit/sandbox.py: gpu, gpu_list, gpu_args, GPU_SYS, GPU_DEVICES, DEV, and the record's gpu.
    • hermit/isolate.py: environment.gpu is validated and passed to the task and tool sandboxes.
    • hermit/defaults.yaml.
    • Needed because the sandbox had no way to show a GPU. Agreed with the maintainer while closing Add ASPIRE: the aspire template and Evolver, with a Robosuite example #74's open item; there is no separate issue.
  • Implementation correctness and failures. Covered by tests:
    • A missing GPU raises at wrap time.
    • Invalid config is refused at load.
    • A run's sandbox is closed on every path, including a failed Popen and a service that is stopping.
    • An output directory replaced by the run, or one that cannot be listed, fails the run instead of being read.
  • Real execution paths and tests.
    • Sandbox side: the GPU test runs CUDA through Sandbox.wrap and checks identity by UUID.
    • ASPIRE side: the tests go through the simulator service over HTTP with bin/sim, through sim.Engine and through sim.confine, using a stand-in cap-harness (FAKE_HARNESS) and a real venv.
    • The stand-in is not ASPIRE: a real ASPIRE run in confine is unverified (see Validation).
  • Reuse the framework's sandbox. Every cap-harness and validator process goes through hermit.sandbox.Sandbox, via sim.confine. Its records (cap-harness-<n>.json) are written under $ASPIRE_OUT/sim-service/sandbox/ and $ASPIRE_OUT/sandbox/; a test checks the service's. No record from a full ASPIRE run is linked, because none was made (see Validation).
  • Sandbox changes are core changes. See Core changes.
  • Tests.
    • Each new test is in its code's group: tests/core/ for the sandbox, tests/methods/aspire/ for ASPIRE.
    • Each fails without its fix; checked by reverting each fix in turn.
    • Durations: the real CUDA test takes about 8 s (skipped without a GPU); the others take under 1.5 s each.
    • A fake /dev (via sandbox.DEV) lets the device-binding test run on machines without a GPU.
    • The ASPIRE tests that run the simulator confined skip, with a reason, without a working bubblewrap (needs_bwrap).
  • This description. Read against the final code.
  • Independent review. Before this PR, a dual review ran 7 rounds: this session plus a fresh Codex gpt-6.1-sol session at high effort each round, every finding verified, 25 or so fixed. The last round found no blocker.
    • Fixed in that review: the venv loss in confinement; host reads through links planted in the output; output replaced by a link to a host directory; directories made unlistable to dodge cleanup; hidden content readable through .git and outputs/; a program named pyvenv.cfg widening the grants; renderer grants too broad (whole directories); no Mesa fallback with an NVIDIA-only ICD; missing provider port 8115; a remote provider unreachable; a GPU test that could not detect an extra GPU.
    • Recorded, not changed:
      • The device binds are writable, so a hermit run as root could change the host's device nodes' modes. A read-only remount makes the GPU unusable (verified), and a normal user cannot change the root-owned nodes (verified).
      • A program that escapes the validator can write its own run's outcome. This is ASPIRE's architecture, and the README documents it.
      • The framework runs a command by its real path, which drops a venv for other callers that start a venv's python by path. That is a framework follow-up.
      • Scheme-default ports 80/443 for a port-less loopback provider URL.
    • Post-PR audit (an independent agent, on a51bf6d, checklists item by item, real-GPU probes on this host): no P1, and the GPU boundary held.
      • P2, fixed: a host CUDA_VISIBLE_DEVICES hid the GPU inside confine.
      • P3s, fixed in 528b024: cap-harness's HOME was its output; the ASPIRE tests failed rather than skipped without bubblewrap; the cap-harness sandboxes wrote no record; the docs overstated the isolation (other GPUs' /sys entries are readable); a wrong ASPIRE_SIM_GPU failed each run after charging its budget (now refused at the service's start); nvidia-uvm was not documented as optional; environment.gpu was not documented as having no effect where nothing is confined.
      • Its corrections to this description (the "nothing changes" claim, the record, test isolation) are applied above.
      • Not re-audited: 528b024, the fixes themselves.

🤖 Generated with Claude Code

haizhongzheng and others added 2 commits November 9, 2026 22:41
…th them

hermit's bubblewrap sandbox had no GPU: CUDA found no device and EGL rendered in
software. environment.gpu (Sandbox(gpu=...)) shows the named NVIDIA GPUs, the N of
/dev/nvidia<N>, and nothing of the others: their devices, the driver's nvidiactl
and, when present, nvidia-uvm, nvidia-modeset and nvidia-caps, and read-only
/sys/devices, /sys/bus/pci, /sys/module/nvidia(_uvm), which CUDA and EGL read to
find them. Inside they count from 0. Off by default.

ASPIRE's generated programs ran unconfined on the host in cap-harness, and ASPIRE's
validator can be bypassed. Every cap-harness process (the simulator service's, the
judge's, the direct actor's) now runs in a sandbox of its own (sim.confine):
- it reads ASPIRE's checkout but not its worked solutions, agents' skills, tests,
  outputs/ or .git;
- it writes only its run's output, and run storage inside the checkout is refused;
- it reaches only the providers (8114/8115/8116/8118, CAP_HARNESS_*_URL ports; a
  remote one through an allowlist proxy);
- it renders on the GPUs ASPIRE_SIM_GPU names.
A venv interpreter keeps its venv. A hand-extracted EGL driver is shown file by
file. The host reads a run's output only after removing links (modes repaired
first), and only from run_dirs inside the run. A program's own directory is never
a trusted grant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r ASPIRE's confined simulator

- The host's CUDA_VISIBLE_DEVICES is not passed into the simulator's sandbox: its
  GPUs count from 0 there, so a host value (=8) left CUDA no device.
- Each confined run gets a HOME of its own, removed after it: caches no longer land in
  the run's output, which is delivered into the session's workspace.
- The service's and the judge's confined runs leave sandbox records
  ($ASPIRE_OUT/sim-service/sandbox/, $ASPIRE_OUT/sandbox/).
- The simulator service refuses to start without bubblewrap or with an ASPIRE_SIM_GPU
  the machine lacks, instead of failing each session's runs after charging its budget.
- The ASPIRE tests that run the simulator confined skip, with a reason, without a
  working bubblewrap.
- Docs: other GPUs' /sys entries stay readable (no access to their devices),
  nvidia-uvm only when present, and environment.gpu has no effect where nothing is
  confined.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@haizhongzheng
haizhongzheng merged commit f469f59 into main Nov 10, 2026
1 check passed
@haizhongzheng
haizhongzheng deleted the sandbox-gpu branch November 10, 2026 04:42
iamziyuzhao added a commit that referenced this pull request Nov 10, 2026
…h branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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