feat(sandbox): add Apptainer backend for HPC environments - #1073
Open
zhiheng-yang wants to merge 3 commits into
Open
feat(sandbox): add Apptainer backend for HPC environments#1073zhiheng-yang wants to merge 3 commits into
zhiheng-yang wants to merge 3 commits into
Conversation
zhiheng-yang
marked this pull request as ready for review
August 31, 2026 01:49
Contributor
There was a problem hiding this comment.
Devin Review found 6 potential issues.
4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
Author
|
Addressed the posted Devin findings in 60f53eb:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(sandbox): add Apptainer backend for HPC environments
What this solves
BenchFlow tasks are usually packaged as Dockerfile build contexts, but Docker is often unavailable on HPC and other shared Linux systems. Those systems commonly provide Apptainer instead.
This PR adds
--sandbox apptainerto the normal evaluation path:bench eval run \ --tasks-dir path/to/tasks \ --agent oracle \ --sandbox apptainer \ --skill-mode no-skillThe provider accepts existing Dockerfile-based task environments and local SIF images. Dockerfile contexts are built into cached SIF images, while each rollout gets a separate writable overlay.
Scheduler allocations, environment modules, and site-specific setup stay outside BenchFlow, so the backend is not tied to Slurm or a particular cluster.
Design
Integration
apptaineruses the existing provider registry, capability checks, and sandbox factory. It is imported lazily, so other providers do not require an Apptainer installation.Image inputs and build
The image layer supports two inputs:
.sifimage.For Dockerfile-based tasks, the backend uses Apptainer's native BuildKit bootstrap:
Why not translate to a
.deffile: doing so reliably would require BenchFlow to reproduce multi-stage builds, build arguments, environment expansion,COPYownership and permissions, shell forms, and.dockerignorebehavior.Instead, BuildKit evaluates the Dockerfile and build context, Apptainer creates the SIF, and BenchFlow owns caching and rollout lifecycle. Existing tasks do not need a second
.deffile, and no Docker daemon is involved.Built images are stored in a content-addressed cache. Construction happens through a temporary output path; the completed image is inspected before an atomic rename makes it visible to other rollouts. An in-process lock prevents duplicate concurrent builds of the same context.
Rollout isolation
Each sandbox receives its own runtime directory, instance name, and writable overlay:
The cached SIF is never modified by a rollout. Agent changes, generated files, package installations, and verifier state are written to the rollout overlay and disappear when that sandbox is deleted.
Instances are started with:
--fakerootfor container-root semantics without host root privileges;--containalland--no-hometo avoid inheriting the user's host environment;--cleanenvto prevent unintended environment leakage;--fakerootdoes not grant host root privileges. It maps the calling user to root inside the container namespace, which preserves the task behavior expected from container images while keeping execution unprivileged on the host. The overlay is what makes this useful for agent workloads: the SIF remains immutable, while package installs and changes under paths such as/root,/app, and/usrare written to rollout-local storage.A readiness probe completes before the sandbox is returned to the rollout. Partial startup failures use the same cleanup path as normal shutdown, preventing abandoned instances and temporary runtime directories.
Execution and agent transport
Commands run through
apptainer execagainst the named instance. A rollout-scoped environment file avoids command-line quoting problems and keeps the host environment separate. Working directories, timeouts, output capture, exit status, sandbox users, and background processes continue to use BenchFlow's existing interfaces.Uploads and downloads use a bound staging directory, while a dedicated log mount keeps artifacts available after teardown.
ApptainerProcesshandles the bidirectional stdin, stdout, and stderr required by long-lived ACP agents; keeping it separate makes process and lifecycle behavior independently testable.Failed builds never replace cached images, and instance cleanup is scoped and idempotent.
Runtime requirements
Dockerfile builds require Apptainer with BuildKit bootstrap support and a compatible rootless BuildKit service:
An existing local SIF does not need BuildKit. Image caches may live on shared storage, while temporary BuildKit and Apptainer state can use node-local storage.
Implementation details by file
sandbox/apptainer_image.pysandbox/apptainer.pysandbox/process/apptainer.pysandbox/process/__init__.pysandbox/providers.pysandbox/setup.pyrollout/__init__.pyTesting
The backend was tested end to end with a subset of SkillsBench tasks on a real HPC system. Oracle and ACP agent runs completed successfully, covering image construction, writable rollout state, verification, artifact collection, and cleanup.