Skip to navigation

Configure Sandboxed Gym for Evaluator

View as MarkdownOpen in Claude

Sandboxed Gym runs NeMo Gym and environment code outside the trusted Evaluator task container. The Evaluator task keeps platform and OpenSandbox credentials, starts a per-run Gym host, sends rollout requests over HTTP, and destroys the host when the run ends.

This page is for platform operators. Job submitters cannot select the host provider, runtime image, PVC, or egress policy.

Prerequisites

  • Complete the shared OpenSandbox platform setup. It configures the server connection, credentials, and top-level platform sandbox capability.
  • A Kubernetes or Volcano Jobs execution profile with a shared job-storage PVC. The claim should support ReadWriteMany when Jobs and OpenSandbox pods can run on different nodes.
  • Published nhx-tasks and nhx-gym-host images for the platform release. Upgrade them together: a Gym host image from an earlier release ignores the job’s env_vars and env_secrets, so its Gym servers start without them.
  • An allowlisted model endpoint reachable from the Gym host.

Execution topology

For a built-in environment, sandboxed execution runs one platform step:

agent-evaluate (nhx-tasks)
→ OpenSandbox
→ nhx-gym-host

For a custom environment FileSet, Evaluator runs two platform steps:

stage-environment (nhx-tasks)
→ shared job PVC
→ agent-evaluate (nhx-tasks)
→ OpenSandbox
→ nhx-gym-host

The Gym host mounts the environment read-only and a separate workspace path read-write.

Configure Evaluator

After completing the shared OpenSandbox setup, add the Evaluator-specific values. Replace the image, PVC, and model URL for your deployment:

platformConfig:
evals:
sandboxed_gym_default: true
sandbox_cluster_capable: true
sandbox_host_provider: opensandbox
sandbox_runtime_image: nvcr.io/nvidia/nemo-helix/nhx-gym-host:<release-tag>
sandbox_job_storage_pvc_claim: nemo-helix-core-storage
sandbox_policy_base_urls:
- http://nemo-helix-api.<namespace>.svc.cluster.local:8080
sandbox_resources:
cpu: "2"
memory: 8Gi

The Evaluator-specific sandbox_cluster_capable flag is separate from the top-level sandboxClusterCapable value configured in the shared setup. Both must be true: the top-level value injects the OpenSandbox connection into Jobs pods, and the Evaluator flag makes its compiler fail closed until the remaining Evaluator settings are configured.

sandbox_job_storage_pvc_claim must match the PVC configured on the Jobs execution profile. Evaluator rejects a FileSet-backed job when staging writes to one claim and OpenSandbox would mount another.

Configuration reference

SettingDefaultPurpose
sandboxed_gym_defaultfalseRun Gym targets in a separate host. Custom environment FileSets require true.
sandbox_cluster_capablefalseConfirm that this Evaluator deployment can provision sandbox hosts.
sandbox_runtime_imageunsetFully qualified nhx-gym-host image containing NeMo Gym and the host runtime.
sandbox_job_storage_pvc_claimunsetShared claim used for staged environments and Gym workspaces.
sandbox_host_provideropensandboxHost provider. docker is for local debugging and is not an isolation boundary.
sandbox_host_provider_options{}Provider-specific connection options. Helm supplies the OpenSandbox protocol separately.
sandbox_environment_sub_pathenvironmentRead-only environment location within job storage.
sandbox_workspace_sub_pathworkspaceRead-write Gym workspace location within job storage.
sandbox_resourcesunsetCPU, memory and ephemeral-storage requests for each Gym host. Set these on shared clusters.
sandbox_policy_base_urls[]Model or inference base URLs the Gym host may reach.
sandbox_egress_allow[]Additional allowed destinations in host:port form.
sandbox_episode_backendopensandboxProvider for nested episode sandboxes requested by an environment.
sandbox_allow_insecure_memory_backendfalseSecond opt-in required for the non-isolating local memory backend.
sandbox_approved_images[]Images allowed for nested episode sandboxes. Empty rejects every episode request.
sandbox_docker_profileunsetImage, settings and extra egress for Gym jobs that set docker: true. Unset refuses those jobs. See Run Docker in Gym servers.

Evaluator requires at least one entry across sandbox_policy_base_urls and sandbox_egress_allow. The OpenSandbox provider applies a deny-by-default policy and adds the trusted episode broker automatically.

Configure model egress

Use sandbox_policy_base_urls for model and inference endpoints:

platformConfig:
evals:
sandbox_policy_base_urls:
- http://nemo-helix-api.nemo-helix.svc.cluster.local:8080
- https://inference-api.nvidia.com/v1

Use sandbox_egress_allow for non-model dependencies:

platformConfig:
evals:
sandbox_egress_allow:
- artifacts.example.internal:443

A package index is not needed for built-in environments, whose virtual environments ship in the nhx-gym-host image, nor for wheels-v1 custom environments: their servers run on the image’s Gym install, and the package’s wheels/ directory supplies everything their requirements.txt files add. Only native-v1 custom environments install from an index at job start; for those, allow pypi.org:443 and files.pythonhosted.org:443, or whichever index mirror the cluster uses.

When sandbox_egress_allow is empty and the job runs a wheels-v1 environment on the OpenSandbox provider, Evaluator starts the host in offline mode: uv never consults an index and the Hugging Face libraries read only from the cache the package vendored. A dependency or dataset the package forgot then fails with a named error at startup instead of a blocked connection later. Any entry in sandbox_egress_allow, or for a docker: true job in the Docker profile’s egress_allow, leaves the host online. The run records the decision as environment_offline in its runner provenance.

Submitters cannot extend these lists from GymRunnerTarget. This prevents an environment from widening its own network access.

Configure credentials

OpenSandbox credentials remain in the trusted Evaluator task. The Gym host receives only per-run tokens and the environment variables required by its selected Gym components.

Each Gym host and episode sandbox also gets its own execd access token. execd, the command server in every OpenSandbox sandbox, then refuses any request without it (execd v1.0.15 or later; an older execd ignores the token), including requests through the OpenSandbox server proxy from a pod that holds the server’s API key. Outside the sandbox, the Evaluator task that created it holds the token, and like the job’s env_secrets values it appears in the sandbox’s pod spec, so anyone allowed to read pods in the sandbox namespace can read it. The Gym host also removes the token from its own environment before it starts anything, so nothing it starts inherits it. On the image that runs Docker (see below), the Gym servers can’t read it at all. On the default image they run as the same user as execd, so they could read it from the process table, but it gives them nothing they can’t already do.

For a job-specific model credential, create a NeMo Helix secret and reference it through GymRunnerTarget.env_secrets:

target:
kind: gym
# ...
env_secrets:
EXTERNAL_MODEL_API_KEY: default/my-model-api-key

A job’s env_vars and resolved env_secrets travel to the Gym host together and may total about 90 KiB; Evaluator refuses a job over that limit.

Do not use env_vars for API keys, tokens, passwords, or other secrets. Evaluator rejects credential-shaped env_vars for sandboxed jobs because environment code can read them.

Timeouts

The job’s own startup_timeout_s and collection_timeout_s apply to sandboxed runs too:

  • startup_timeout_s (default 240s) bounds how long the Gym host may take to report ready once its sandbox is running. Pulling the nhx-gym-host image is not counted against it.
  • collection_timeout_s bounds the whole collection, from the first rollout request to the last, however many requests the rollouts are split across. When it is exceeded, the job fails with a collection_timeout_s error and the Gym host is destroyed.
  • collection_timeout_s: null (the default) sets no collection deadline. The Gym host still stops when its sandbox lifetime ends, four hours after creation.

Three more timeouts bound the sandbox creation itself. They must agree, because the OpenSandbox server holds the create request open until the sandbox pod is Running:

TimeoutWhere it is setValue
Host ready waitFixed for Evaluator jobs900s
OpenSandbox SDK request timeoutsandbox_host_provider_options.connection.request_timeout_sFor the create call, defaults to the host ready wait plus 30s. Every later call uses the SDK default of 30s
Server create waitOpenSandbox server sandbox_create_timeout_seconds900s in the example server values

The SDK request timeout must be longer than the server create wait. When it is shorter, a node that still has to pull the nhx-gym-host image fails the job with OpenSandbox did not answer the create request within the SDK request timeout, caused by the SDK’s Request timed out, while the server is still creating the sandbox. Set it only when the server create wait is longer than the default:

platformConfig:
evals:
sandbox_host_provider_options:
connection:
request_timeout_s: 1200

Install an agent CLI into the Gym host

Gym’s CLI agents, such as Codex, Claude Code, and OpenCode, install their CLI at startup unless it is already on PATH. To skip that download or pin a version without rebuilding nhx-gym-host, install the CLI from an agent bundle image:

platformConfig:
evals:
sandbox_host_provider_options:
agent_bundle:
image: registry.example.com/agent-bundles/codex:0.142.5
installer: /bundle/install
entrypoint: bin/codex

The OpenSandbox server’s nemo-agent-bundle extension runs installer /installed-agent from image in an init container and mounts the result read-only into the host. The host puts the directory containing entrypoint first on PATH and runs entrypoint --version before starting. If that fails, the host never becomes ready and the job fails at its startup timeout.

The bundle is a deployment setting: every Gym job on the deployment gets the same CLI. It requires the OpenSandbox provider with the NeMo extension installed, and a bundle built for the nhx-gym-host image’s architecture and C library. Evaluator rejects agent_bundle with the docker provider.

Run Docker in Gym servers

Some environments start containers from a resource server, for example with docker compose up, and some agents run docker themselves. The nhx-gym-host-podman image supports both with rootless Podman behind the Docker CLI. Each compose project gets its own network with service-name DNS, and the Gym host’s egress policy still applies to every container.

A job asks for Docker with docker: true on its Gym target. Only those jobs get the Docker-enabled image, its privileged setup, its container storage and the extra egress, all from the deployment’s sandbox_docker_profile. Every other Gym job keeps the plain nhx-gym-host image. A job that sets docker: true is refused at submit when the deployment has no sandbox_docker_profile, runs Gym in the job container, or uses the local docker host provider.

The image’s setup needs SYS_ADMIN, which only a Kata VM contains. Point the platform at an OpenSandbox server that creates every sandbox with a Kata runtime class: the bootstrap.execd.isolation extension grants SYS_ADMIN when the sandbox is created, before anything in it runs. The Gym host also checks for a Kata VM and fails the job instead of running the setup anywhere else. The server’s execd image must be v1.0.15 or later: execd keeps root, and only from that release does it require the per-sandbox token described under credentials.

Agent servers and resource servers run in the same Gym host, so they share one Podman service: a resource server can inspect the containers an agent started. The docker CLI finds the service through the image’s DOCKER_HOST and also at its default socket, so it works from an agent’s shell tool that starts commands with only the agent’s own variables, such as a registered Deep Agents agent with a local shell backend. Rollouts that run concurrently share the service too, so give each rollout’s compose project its own name, for example with docker compose -p or COMPOSE_PROJECT_NAME.

After setup, the Gym servers run as an unprivileged user with no capabilities, an empty capability bounding set and no_new_privs, so no setuid program in the image can give capabilities back. The job’s env_vars and env_secrets reach Gym only after that, never the root setup. NET_ADMIN is never granted, so nothing in the host can change its network or egress rules. Gym servers use the docker CLI, which only talks to the Podman service’s socket.

The image isn’t published yet. Build it from the repository with the nhx-gym-host-podman-docker bake target and push it to a registry your cluster can pull from:

IMAGE_REGISTRY=<your-registry> BAKE_TAG=<tag> docker buildx bake nhx-gym-host-podman-docker \
--set 'nhx-gym-host-podman-docker.output=type=registry'
platformConfig:
evals:
sandbox_docker_profile:
runtime_image: <your-registry>/nhx-gym-host-podman:<tag>
# Merged over sandbox_host_provider_options, nested keys included.
host_provider_options:
create:
extensions:
bootstrap.execd.isolation: enable
# Added to sandbox_egress_allow: every registry the environment's images come from,
# including its blob storage hosts.
egress_allow:
- registry-1.docker.io:443
- auth.docker.io:443
- production.cloudflare.docker.com:443
- production.cloudfront.docker.com:443
target:
kind: gym
docker: true
# ...

GPU access is not supported yet.

Container storage

Images, containers and volumes live in one ext4 filesystem inside a sparse file in the Gym host’s ephemeral storage. Its size is a ceiling for everything the job’s rollouts pull and write together, not an allocation: the file takes node disk only as data is written. The exception is the filesystem’s journal, written when the file is formatted, whose size steps up with the configured size and stops at 1 GiB:

Configured sizeJournalNode disk used before anything is written
16–32 GiB (the default 30Gi)128 MiB134 MiB at 30Gi
32–64 GiB256 MiB262 MiB at 40Gi
64–128 GiB512 MiB519 MiB at 100Gi
128 GiB and larger1 GiBabout 1 GiB

The first three rows were measured in a Kata sandbox; the last follows from the journal size. The file holds slightly less than its size, since ext4 keeps some for itself. It lasts as long as the Gym host, so every job starts empty.

platformConfig:
evals:
sandbox_docker_profile:
# ...
# The ceiling, as a Kubernetes quantity. Unset means 30Gi; the minimum is 1Gi.
container_storage_size: 100Gi
# Give space freed by deleted images and containers back to the node during the job.
container_storage_discard: true
# Merged over sandbox_resources. Reserve node disk for the host: the storage plus what the
# host writes outside it.
resources:
ephemeral-storage: 110Gi
  • Discard. Without it, space freed inside the file stays allocated on the node until the Gym host ends. With it, every delete also frees the space on the node, which costs some extra I/O.
  • Reserving disk. The size reserves nothing. Without an ephemeral-storage request, the scheduler doesn’t account for the host’s disk use, and hosts that fill their storage can put a node under disk pressure, where Kubernetes evicts pods. A request makes the scheduler place each host only where that much disk is free, so it also limits how many hosts fit on a node. Setting it in the profile’s resources reserves disk for docker: true jobs only. Requests are sent in whole GiB, rounded up, and must not exceed an ephemeral-storage limit set in create.resource of the merged host provider options.
  • Upgrades. Upgrade the Evaluator and the Gym host image together before setting these: an older Docker-enabled image ignores discard.

To pull private images, create a NeMo Helix secret holding the registry token and pass it to the job through env_secrets, like any other job credential. Add the registry, and the host it redirects image layers to, to the profile’s egress_allow. For nvcr.io, that’s nvcr.io:443 and layers.nvcr.io:443.

target:
kind: gym
docker: true
# ...
env_vars:
REGISTRY_USER: $oauthtoken
env_secrets:
REGISTRY_PASSWORD: default/ngc-registry-token

The resource server logs in before it pulls:

subprocess.run(
["docker", "login", "nvcr.io", "-u", os.environ["REGISTRY_USER"], "--password-stdin"],
input=os.environ["REGISTRY_PASSWORD"].encode(),
check=True,
)

The login is stored for the Gym host’s container user, so every Gym server in the host can pull with it.

Local Docker provider

Set sandbox_host_provider: docker only when debugging the runtime contract on a local deployment. It runs the same nhx-gym-host image but does not enforce the OpenSandbox egress policy and is not an isolation boundary.

The memory episode backend is also local-only. It requires both:

sandbox_episode_backend: memory
sandbox_allow_insecure_memory_backend: true

Ordinary evaluations do not create nested episode sandboxes. Environments that request them must use the OpenSandbox episode backend and list every permitted image in sandbox_approved_images.

Verify the deployment

Before accepting custom environment jobs, verify:

  1. OpenSandbox is ready and reachable over the configured in-cluster protocol.
  2. The selected Jobs profile uses Kubernetes or Volcano and mounts the configured PVC.
  3. nhx-tasks and nhx-gym-host can be pulled by pods in the platform namespace.
  4. The Gym host can reach each configured model URL but cannot reach an unlisted destination.
  5. A completed and a failed run both destroy their Gym hosts.

The repository’s sandboxed Gym end-to-end tests check part of items 4 and 5 against a running deployment. They submit a small custom environment whose verifier probes the network and storage from inside the Gym host:

  • Item 4, for one model URL: the one the tests call, which is the platform API unless they are given a real model. They also check that the Kubernetes API, a public address, and a public name are unreachable. They do not read sandbox_policy_base_urls, so to check another configured model URL, run them again with NHX_E2E_GYM_POLICY_ROUTE set to it, NHX_E2E_GYM_POLICY_MODEL set to a model it serves, and the endpoint’s key as the section linked below describes.
  • Item 5, for a run that completes and a run that fails after its Gym host is ready. They watch the cluster for the host’s removal.

They need a source checkout and kubectl access to the cluster. See Sandboxed Gym evaluation for the settings and the command.