nemo_gym.agents.utils.sandbox_python
nemo_gym.agents.utils.sandbox_python
A Python harness’s private runtime, built on the Agent Server host and uploaded into the task sandbox.
The sandbox needs no network, no uv and no Python of its own. For each sandbox platform, the host downloads a
pinned python-build-standalone CPython and checks its SHA-256, then installs the harness’s requirements for that
platform with uv into a separate site-packages archive. Packages are pinned to the versions installed in this
Agent Server’s environment, so the sandbox runs the versions the adapter is tested with. Requirements given as
direct URLs, such as a harness pinned to a commit, are built from source on the host; every other package must
publish a wheel for the sandbox’s platform. Both archives are cached on the host under sandbox_python in Gym’s
cache_dir.
In the sandbox, install_python_runtime.sh unpacks the archives in a private directory, checks that the runtime
imports the harness, and renames it into place, so a concurrent seed never sees a partial runtime. The runtime
lives under /tmp, outside the task’s working directory and HOME, and every command runs from /.
Module Contents
Classes
Functions
Data
API
The sandbox’s CPU architecture and C library, which select the Python build and the wheels.
The uv pip --python-platform value whose wheels run in the sandbox.
A harness’s private Python in the sandbox: the pinned CPython with requirements installed.
import_check is Python source that runs without error only in a usable runtime, for example
"import run_agent, mcp". overrides are the uv overrides the adapter’s own environment is installed with,
such as the lines of its overrides.txt.
Sandbox directory keyed by everything that goes into the runtime.
A runtime found there, such as one an earlier session left in this sandbox, was built from the same inputs and
is reused. The key covers every index-installed version in this Agent Server’s environment, so a runtime
baked into an image is reused only by an Agent Server environment with exactly those versions. The adapter
may keep its own harness files here, beside python/.
The runtime’s interpreter in the sandbox, once is_installed() passes or install() returns.
Run an absolute harness script with -E -s: ignore the task’s Python environment settings and user
site-packages without changing the environment inherited by tool subprocesses. The script directory
must belong to the harness, so task files cannot shadow its imports.
Build the runtime for the sandbox’s platform on this host if needed, then upload and publish it.
timeout_s bounds the whole installation, including a build that another seed started. Raises
RuntimeError when the platform is unsupported, the host build or download fails, or the runtime fails
its import check in the sandbox, and TimeoutError when timeout_s runs out.
Whether the runtime in the sandbox passes import_check. The existence of the directory proves nothing.
Like the installer’s checks, it runs with HOME in the runtime directory, because some harnesses write
their state under HOME when imported.
name==version for each package this server’s environment installed from an index.
Passed to uv as constraints, which keep the extras that dependencies request (an override would replace
lxml[html_clean] with plain lxml). Packages installed from a URL or a path, including editable ones,
are left free.
Where the host keeps the archives: sandbox_python under Gym’s cache_dir.
path, built once per host. Builders write atomically, so other processes see it whole or not at all.
Concurrent callers share one build and its outcome, and a caller that is cancelled leaves it running for the others. A failed build is retried by the next call.
Remove path from the sandbox, best effort. Cancelling the caller does not stop the removal.
The proxy the host’s environment names for url. Gym’s shared HTTP client does not read it itself.
The pinned python-build-standalone archive for platform, checked against its published SHA-256.
Names of the requirements given as direct URLs; uv builds these from source on the host.
Ask the sandbox for its kernel, machine and C library.