Skip to content

chore(agent): deprecate the legacy /run path of *_sandboxed_agent harnesses - #5222

Merged
yaoyu-33 merged 3 commits into
mainfrom
chore/deprecate-sandboxed-agents
Oct 30, 2026
Merged

yaoyu-33 merged 3 commits into
mainfrom
chore/deprecate-sandboxed-agents

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Some new work is still being built on the *_sandboxed_agent harnesses. These harnesses run each episode through their own legacy /run; on an environment server, that goes through the legacy_agent relay. The replacement is the base agent running sandbox sessions under an environment server (single_agent_turn / single_agent_turn_legacy). The legacy path will be removed at the end of the environment-server migration. This PR removes nothing and migrates nothing. It does two things:

  1. Discourages new development. Each of the five agent READMEs opens with a deprecation banner. The Fern page Integrate Existing Agents and the add-benchmark skill now steer new work to the session harnesses.
  2. Tells current users at runtime. When one of these agent servers starts on the deprecated path, it logs one WARNING through its module logger. Only the main process logs; uvicorn workers of a multi-worker server skip it. The warning names the agent, says the path is deprecated and will be removed, names the replacement, and points to a doc. Subclasses inherit it: vibench_agent extends OpenCodeSandboxedAgent, so it logs the OpenCode warning too.

It follows the existing deprecation pattern in nemo_gym/global_config.py (logger.warning("DEPRECATED: ...") for the generated legacy_agent relays). Each agent keeps its own message constant and a functools.cache'd _warn_deprecated_once() that returns early when is_nemo_gym_fastapi_worker() is true, so the code goes away with the agent and no shared core helper is added.

Replacements

Deprecated When it warns Replacement named in the warning and README
opencode_sandboxed_agent always at startup Where the resources server returns sandbox_access, a session harness it lists in allowed_agents: opencode_agent for Terminal Bench 2.1, pi_agent or codex_agent for SWE-bench Pro. No session path yet for the SWE servers that return only a sandbox_handle, the HLE search presets (tool_servers) or vibench_agent; the warning says so
pi_sandboxed_agent always at startup pi_agent with sandbox sessions (responses_api_agents/pi_agent/README.md § Configure and run). The HLE search presets (tool_servers) have no session path yet; the warning says so
hermes_sandboxed_agent always at startup hermes_agent with sandbox sessions (responses_api_agents/hermes_agent/README.md § Configure and run)
terminus_2_sandboxed_agent only with resources_server set (the legacy /run path) Its own episode sessions under the harbor environment server for Harbor task folders, including gym eval run terminal_bench_2_1; otherwise a session-capable harness (pi_agent, codex_agent, opencode_agent, openclaw_agent; see benchmarks/terminal_bench_2_1/README.md "Choose a harness")
miniswe_sandboxed_agent only with resources_server set (the legacy /run path) Its own episode sessions (README § Harbor episodes), including gym eval run terminal_bench_4. Terminal-Bench-Science has no session path yet; the warning says so

Terminus 2 and mini-SWE are scoped to /run on purpose. Both gained episode sessions under an environment server in #3729 and #3745. That session path is what gym eval run <harbor tasks> --agent terminus_2_sandboxed_agent uses, and the Terminal-Bench 2.1 Harbor tutorial recommends it. Their /run route already describes itself as "the legacy /run path". It needs a resources_server, and the Harbor run config sets that to null. So these two agents warn only when resources_server is set. A startup warning on every run would have flagged the session path as deprecated, but that path is the replacement.

hermes_sandboxed_agent is kept to a minimal change (banner, warning, one test) because #3966 removes it outright.

Exact warning text

DEPRECATED: opencode_sandboxed_agent runs each episode through its own legacy /run path and will be removed after the environment-server migration. Where the resources server returns sandbox_access, switch to a session harness in its allowed_agents under an environment server: opencode_agent where listed (Terminal Bench 2.1), otherwise another such as pi_agent or codex_agent (SWE-bench Pro). Setups with no session path yet keep working here: SWE resources servers that return only a sandbox_handle (swebench, swe_gym, r2e_gym and others), the HLE search presets (tool_servers) and vibench_agent. See responses_api_agents/opencode_agent/README.md#environmentserver-sessions.
DEPRECATED: pi_sandboxed_agent runs each episode through its own legacy /run path and will be removed after the environment-server migration. Use pi_agent with sandbox sessions under an environment server instead. The HLE search presets, which use tool_servers, have no session path yet and keep working here. See responses_api_agents/pi_agent/README.md#configure-and-run.
DEPRECATED: hermes_sandboxed_agent runs each episode through its own legacy /run path and will be removed after the environment-server migration. Use hermes_agent with sandbox sessions under an environment server instead. See responses_api_agents/hermes_agent/README.md#configure-and-run.
DEPRECATED: terminus_2_sandboxed_agent is configured for its legacy /run path (resources_server is set), which will be removed after the environment-server migration. For Harbor task folders, run it on episode sessions under the harbor environment server (gym eval run <tasks> --agent terminus_2_sandboxed_agent; for TB 2.1, gym eval run terminal_bench_2_1 --agent terminus_2_sandboxed_agent); for other benchmarks, use a session-capable harness such as pi_agent, codex_agent or opencode_agent. See responses_api_agents/terminus_2_sandboxed_agent/README.md.
DEPRECATED: miniswe_sandboxed_agent is configured for its legacy /run path (resources_server is set), which will be removed after the environment-server migration. Run Harbor tasks on episode sessions instead (gym eval run <tasks> --agent miniswe_sandboxed_agent; for TB4, gym eval run terminal_bench_4 --agent miniswe_sandboxed_agent). Terminal-Bench-Science has no session path yet and keeps working here. See responses_api_agents/miniswe_sandboxed_agent/README.md#harbor-episodes.

Compatibility

The only behavior change is the log line. Nothing raises, and configs, allowed_agents, benchmark presets and the request path are unchanged.

Docs and skills

  • Changed: fern/versions/latest/pages/agent-server/integrate-existing-agents.mdx gets a <Warning> after the paragraph that lists the older adapters.
  • Changed: .agents/skills/add-benchmark/SKILL.md (Step 4) points new sandboxed-harness benchmarks to the session harnesses.
  • Left alone:
    • evaluation/harness.mdx and reference/cli-commands.mdx: they document the --agent-type swap mechanism on shipped presets. Changing those examples would need a validated session-harness swap, which this PR does not establish.
    • evaluation-tutorials/terminal-bench-2-1-harbor.mdx and data/harbor-tasks.mdx: they use Terminus 2 episode sessions, which are not deprecated.
    • reference/trajectory-capabilities.mdx: a capability description.
    • The hermes_sandboxed_agent mentions in agent-server/add-or-update-a-harness.mdx: refactor(hermes): remove standalone sandboxed agent #3966 edits that page.
    • Release notes and individual benchmark READMEs.

Validation

Run on macOS (Darwin, arm64) from the worktree's uv venv, against the final diff (f81e80a8d, after merging main):

Command Result
gym env test +entrypoint=responses_api_agents/terminus_2_sandboxed_agent pass: 138 passed, 4 skipped (existing terminal/PTY skips)
gym env test +entrypoint=responses_api_agents/miniswe_sandboxed_agent pass: 168 passed, 1 skipped (existing)
gym env test +entrypoint=responses_api_agents/opencode_sandboxed_agent pass: 71 passed
gym env test +entrypoint=responses_api_agents/pi_sandboxed_agent pass: 51 passed
gym env test +entrypoint=responses_api_agents/hermes_sandboxed_agent pass: 81 passed, 1 skipped (existing)
pytest responses_api_agents/vibench_agent/tests/ (inherits the OpenCode warning) pass: 17 passed
pre-commit run --files <the 17 touched files> pass: ruff, ruff-format, whitespace, guardwords; no files modified
cd fern && npm run check pass: 0 errors; 1 warning (missing-redirects check skipped, not authenticated)

The deprecation tests were rerun after the final wording change: they passed (12 in total across the five agents).

Run in parallel, the OpenCode and mini-SWE suites each failed once: test_import_only_loads_shared_opencode_modules hit its 30 s subprocess timeout, and test_real_runner_preserves_model_history_and_tool_observations[present-*] failed. Both tests pass on their own, and both full suites pass when run one at a time (counts above).

New tests: test_only_the_main_process_logs_the_deprecation_once[False/True] (OpenCode, Pi, Hermes) and test_only_the_legacy_run_configuration_logs_the_deprecation_once (Terminus 2 and mini-SWE: legacy main process, session main process, legacy worker). Each one builds the agent server twice and checks the WARNING records from the agent's module logger. The main process must get exactly one record with the message. A worker (IS_NEMO_GYM_FASTAPI_WORKER=1) must get none, and so must Terminus 2 or mini-SWE without a resources_server. Removing the worker gate, the cache, or the resources_server condition each makes at least one case fail.

Not run: pre-commit run --all-files, gym dev test and gym env test --all. No core library, CI, or shared-test-infrastructure file changed. Not run either: a real multi-worker server start. The one-line count follows from run_webserver, which builds the server in the main process before it sets the worker flag.

Rollout evidence: N/A — warning log and docs only; no change to agent or verifier behavior.

Issue

Tracking is internal; no public GitHub issue found (gh issue list --repo NVIDIA-NeMo/Gym --search "sandboxed deprecate").

Possible follow-up, out of scope here: harness_agent.

🤖 Generated with Claude Code

…nesses

New work is still being built on the sandboxed harnesses that run each
episode through their own legacy /run (behind a legacy_agent relay). The
replacement is a session harness under an environment server. The path
will be removed after the environment-server migration; this commit only
announces that.

- opencode_sandboxed_agent, pi_sandboxed_agent and hermes_sandboxed_agent
  log one DEPRECATED warning per process at startup, naming the
  replacement (opencode_agent, pi_agent, hermes_agent) and its README.
- terminus_2_sandboxed_agent and miniswe_sandboxed_agent warn only when a
  resources_server is set, which selects their legacy /run path. Their
  episode sessions (#3729, #3745), which Harbor task runs use, are not
  deprecated.
- Each README opens with a deprecation banner. The Integrate Existing
  Agents page and the add-benchmark skill steer new work to session
  harnesses.

No behavior change beyond the log line.

Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 28, 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.

@yaoyu-33 yaoyu-33 added support User questions, support, or maintenance requests area:agent Agent harnesses and Responses API agent behavior complexity:low Localized change in one scope with a small, straightforward review surface labels Oct 28, 2026
@yaoyu-33
yaoyu-33 marked this pull request as ready for review October 28, 2026 22:13
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 28, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 6fd9206

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP

LGTM — no concerns found. Reviewed all 17 changed files and traced startup hooks, OpenCode inheritance, legacy-versus-session configuration, and migration references. Terminus 2 and mini-SWE session-only configurations remain exempt from the deprecation warnings.

Static review only; tests and documentation builds were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: SHIP. The banners, the Fern warning and the add-benchmark line steer new work well. Limiting the Terminus 2 and mini-SWE warning to the /run configuration is the right call: Harbor episode runs clear resources_server, so they stay quiet.

There are three inline NOTEs. All of them are about what the warning tells people to do:

  • The OpenCode replacement works only where the resources server returns sandbox_access. The SWE servers that return a sandbox_handle cannot switch yet.
  • The mini-SWE hint resources_server: null makes every /run return 422 for users of the TB4 and TB-Science presets.
  • A server with several workers prints the warning 2N+1 times, so 9 times with the shipped num_workers: 4.

Checked and fine

  • Every README anchor, Fern route and add-benchmark link resolves.
  • The warning does reach the console. gym env start runs python app.py, and without root handlers the record goes to stderr through logging.lastResort.
  • The resources_server gate is right for every shipped config: the presets that set it go through legacy_agent, and the Harbor CLI clears it.
  • Each of the five new tests fails if the call is removed, the cache is dropped, the text changes, or the Terminus/mini-SWE condition is inverted. The full suites match the counts in the PR body: OpenCode 70; Pi 50; Hermes 80, 1 skipped; Terminus 2 137, 4 skipped; mini-SWE 167, 1 skipped; vibench 17.

Not verified: a real multi-worker agent server start. The duplicate count comes from a reduced uvicorn 0.37.0 reproduction. No GPU or live sandbox runs either.

yaoyu-33 and others added 2 commits October 29, 2026 12:57
…oxed-agents

Signed-off-by: yaoyu-33 <[email protected]>

# Conflicts:
#	fern/versions/latest/pages/agent-server/integrate-existing-agents.mdx
…acements

Address the review on the deprecation warnings:

- Skip the warning in uvicorn workers. The main process builds the server
  and warns before it marks itself as a worker, so a multi-worker server
  now logs one line instead of 2N+1.
- OpenCode: send users to a session harness the resources server lists in
  allowed_agents (opencode_agent for Terminal Bench 2.1, pi_agent or
  codex_agent for SWE-bench Pro), and name the setups with no session path
  yet: sandbox_handle-only SWE servers, the HLE search presets and
  vibench_agent.
- mini-SWE: replace the `resources_server: null` hint, which makes /run
  return 422, with the Harbor session commands, including TB4's, and say
  that Terminal-Bench-Science has no session path yet.
- Pi: the HLE search presets use tool_servers and stay on this agent.
- Terminus 2: name the TB 2.1 Harbor session command.

Tests now also check that a worker process logs nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test f81e80a

@yaoyu-33
yaoyu-33 enabled auto-merge October 29, 2026 18:10
@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 29, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41075266060

Merged via the queue into main with commit 2831477 Oct 30, 2026
90 of 101 checks passed
@yaoyu-33
yaoyu-33 deleted the chore/deprecate-sandboxed-agents branch October 30, 2026 15:31
yaoyu-33 added a commit to yaoyu-33/Gym that referenced this pull request Oct 30, 2026
Resolves modify/delete conflicts in `responses_api_agents/hermes_sandboxed_agent/` (README.md,
app.py, tests/test_app.py) by keeping this branch's deletion. NVIDIA-NeMo#5222 added a deprecation warning to
that adapter's legacy `/run` path, saying it will be removed; this branch removes it.

NVIDIA-NeMo#5222 also listed `hermes_sandboxed_agent` among the legacy agents not to build on, in the
add-benchmark skill and in integrate-existing-agents.mdx. Drop it from both lists, since the
adapter no longer exists; the warning still covers the remaining sandboxed agents.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
khazic pushed a commit to khazic/Gym-lao that referenced this pull request Nov 24, 2026
…ode configs to claude_code_agent and deprecate harness_agent (NVIDIA-NeMo#5821)

* feat(job_bench): serve typed resources sessions that lend the task sandbox

JobBenchResourcesServer now subclasses SandboxSessionResourcesServer, so an
Environment Server can seed an episode session, hand the agent the task
sandbox through sandbox_access (operate scope, workdir /workspace), verify,
and close. Verify archives /workspace/output once, stops the sandbox, and
replays the first verdict to an identical retry; a verify after close is
masked. Close stops the sandbox if verify did not and fences late seeds; a
session that is never closed expires with the sandbox's ttl_s, and shutdown
stops what is left.

harness_agent's /run seed still returns the sandbox descriptor, and its
verify still stops the sandbox.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* feat(job_bench): run the Codex, Hermes and Pi configs through single_agent_turn_legacy

benchmarks/job_bench/{codex,hermes,pi}.yaml drop harness_agent behind
legacy_agent. single_agent_turn_legacy now seeds the resources server, lends
its task sandbox to codex_agent, hermes_agent or pi_agent, closes the agent
before grading, and closes the resources session. The harness settings carry
over (system prompt, model, version pins, turn and token limits, 2-hour agent
budget, concurrency 32), and the episode deadline stays inside the sandbox's
ttl_s. claude_code.yaml stays on harness_agent for now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* feat(workspace_bench): serve typed resources sessions that lend the task sandbox

WorkspaceBenchResourcesServer now subclasses SandboxSessionResourcesServer, so
an Environment Server can seed an episode session, hand the agent the task
sandbox through sandbox_access (operate scope, workdir /workspace), verify,
and close. The inputs stay frozen on the server from seed: verify captures the
sandbox's input and output together with them, stops the sandbox, and judges;
an identical retry replays the verdict or rejudges the same capture. A verify
after close is masked. Close stops the sandbox if verify did not, drops the
frozen inputs and fences late seeds; expiry and shutdown stop what is left.

harness_agent's /run seed still returns the sandbox descriptor and still gets
409 on a repeat; its verify still stops the sandbox.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* feat(workspace_bench): run the Codex, Hermes and Pi configs through single_agent_turn_legacy

benchmarks/workspace_bench/{codex,hermes,pi}.yaml drop harness_agent behind
legacy_agent. single_agent_turn_legacy now seeds the resources server, lends
its task sandbox to codex_agent, hermes_agent or pi_agent, closes the agent
before judging, and closes the resources session. The harness settings carry
over (system prompt, model, version pins, turn and token limits, 2-hour agent
budget, concurrency 32), and the episode deadline leaves room for a queued
judge run inside the sandbox's ttl_s. claude_code.yaml stays on harness_agent
for now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* feat(job_bench,workspace_bench): run the Claude Code configs through single_agent_turn_legacy

benchmarks/{job_bench,workspace_bench}/claude_code.yaml drop harness_agent
behind legacy_agent for claude_code_agent, which borrows the task sandbox the
resources server lends. The Claude Code settings carry over (model, API key,
max_turns 100, the 2-hour budget, bare false, the 2.1.261 pin, the system
prompt, concurrency 32); without bare, Claude Code still discovers the
Workspace-Bench office skills linked into /workspace/.claude/skills. No
shipped job_bench or workspace_bench config uses harness_agent now; both
servers list claude_code_agent first in allowed_agents and keep
harness_agent's /run seed for compatibility.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* chore(harness_agent): deprecate the agent

harness_agent runs each episode through its own legacy /run path behind a
legacy_agent relay. Its job_bench and workspace_bench configs now run on the
harnesses' own session agents, so the agent logs one DEPRECATED warning per
process at startup (not in uvicorn workers) and its README opens with a
deprecation banner, as NVIDIA-NeMo#5222 did for the sandboxed agents. The warning names
the replacements and the configs that still use it (swe_atlas_qa, rna_design);
harness_exa_search still builds on its agent registry. No behavior change
beyond the log line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* fix(workspace_bench): grade the files the agent left, keep frozen inputs with their sandbox, and own the judge sandbox

- Collection recreates /workspace/input and /workspace/output before archiving and accepts tar's exit 1
  (a file the agent's process changed mid-read), so folders the agent removed or left changing are graded
  instead of failing verify and masking the episode. Only a sandbox or archive failure fails the verify.
- The frozen inputs are dropped only when the task sandbox stops, so a collection whose stop also failed
  can be retried instead of failing with a KeyError until close.
- A harness_agent verify that fails while saving its inputs and request (artifact_root) now stops the task
  sandbox; an agent-run session gets no close, so it stayed up until shutdown.
- The judge sandbox is registered as the session's verifier sandbox and stopped through the base's
  shielded stop, so a cancelled verify still stops it and close or shutdown retries a failed stop.
- A metadata.json that does not parse or a manifest entry without stored_relpath/filename gets 422
  before any sandbox starts, instead of a retried 500.
- The cookie arm of /seed_session rejects a malformed typed seed (reject_partial_typed_seed).
- The capture is written to disk off the event loop.
- Tests: the archive fixture is built once, since gzip stamps the time into its header.
- Configs: use_absolute_ip: true, so the in-sandbox agent reaches the model server; Codex grades a run
  whose CLI exited with an error and inherits the image environment, as harness_agent did; Pi's
  per-command bash limit is the agent budget; unused API-key keys are dropped. READMEs say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* fix(job_bench): grade the output the agent left, and stop agent-run sandboxes on every verify failure

- Collection recreates /workspace/output before archiving and accepts tar's exit 1 (a file the agent's
  process changed mid-read), so an output folder the agent removed or left changing is graded instead of
  failing verify and masking the episode. Only a sandbox or archive failure fails the verify.
- A harness_agent verify that fails while saving its request and rubrics (artifact_root) now stops the
  task sandbox, as main did; an agent-run session gets no close, so it stayed up until shutdown.
- The cookie arm of /seed_session rejects a malformed typed seed (reject_partial_typed_seed) instead of
  starting an agent-run sandbox for it.
- The seed's task archive, the output archive write and its extraction run off the event loop.
- Configs: use_absolute_ip: true, so the in-sandbox agent reaches the model server; Codex grades a run
  whose CLI exited with an error and inherits the image environment, as harness_agent did; Pi's
  per-command bash limit is the agent budget; unused API-key keys are dropped.
- READMEs: the model-server address, Codex and Pi need egress, and the harness_agent path's changed
  answers (masked instead of 400, 422 instead of 500).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* fix(harness_agent): reach the model server from the Claude Code sandboxes, and say which harnesses cannot move yet

- benchmarks/{job_bench,workspace_bench}/claude_code.yaml set use_absolute_ip: true, like their Codex, Hermes
  and Pi siblings: claude_code_agent hands the in-sandbox CLI the server address as configured, while
  harness_agent used to rewrite a loopback host to this host's address.
- The deprecation banner and warning name the harnesses with no session agent to move to (cline, prime,
  simple_strands, deepagents), so removal waits on them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* fix(job_bench): give the session configs an episode deadline that covers a slow grade

The 9000 s deadline left 1800 s around the agent's 7200 s budget, but sandbox
start may take 1200 s, agent CLI setup up to 1200 s outside the agent's
timeout, and one round of rubric judging about 900 s, so a slow grade timed
out and reran the whole 2-hour episode. 11400 s covers the slowest scored
path. Verify still starts well before the session's ttl_s ends, the task
sandbox is stopped after output collection, and the judge runs on the
resources server host.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* fix(workspace_bench): give the session configs an episode deadline that covers a slow grade

The 10200 s deadline equals task sandbox start (1200 s), the agent's 7200 s,
judge sandbox start (1200 s) and the judge's 600 s, with nothing left for
agent CLI setup (up to 1200 s, outside the agent's timeout), collection, or a
wait for one of the server's 10 judge slots, which 32 concurrent episodes
share. A slow grade timed out and reran the whole 2-hour episode. 18000 s
covers the slowest scored path, including a wait behind three judge runs.
Verify still starts well before the session's ttl_s ends, the task sandbox is
stopped after collection, and the judge runs in a sandbox of its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* fix(job_bench,workspace_bench): give the Claude Code configs the deadlines of the other harnesses

The Claude Code configs kept the 9000 s and 10200 s episode deadlines that
NVIDIA-NeMo#5816 and NVIDIA-NeMo#5817 raised to 11400 s and 18000 s, so a slow grade timed out and
reran the 2-hour episode only for Claude Code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* docs(harness_agent): name what still blocks removing the agent

Main now serves sandbox sessions with a lent sandbox in cline_agent, prime_agent, simple_strands_agent and
langchain_deepagents_agent, so the banner and warning no longer say those harnesses have nothing to move to.
What blocks swe_atlas_qa is its resources server, which does not lend its task sandbox; rna_design forwards
required MCP tools to Claude Code, which claude_code_agent does not accept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

* docs(harness_agent): say where the shared sandbox handling lives on the session path

harness_agent was built to keep sandbox handling in one server. The banner now says where that handling lives
for the session agents that replace it: the resources server base that starts, lends and stops the task sandbox,
the environment server that orders the episode, and the launch and stop helpers in nemo_gym/agents/utils/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

---------

Signed-off-by: yaoyu-33 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
ehosseiniasl pushed a commit to ehosseiniasl/Gym that referenced this pull request Nov 24, 2026
…r servers that sandboxed code calls (NVIDIA-NeMo#6161)

* feat(core): session secrets, cookie names and MCP endpoint options for servers that sandboxed code calls

A resources server that lends a sandbox is reached by code the model controls, so the session key that every
caller can compute from the server's class and name must not sign its cookies and MCP tokens, and its endpoint
should look like an ordinary one.

- SimpleServer.get_session_secret() signs session cookies and MCP session tokens (default: the session middleware
  key, so nothing changes). Session routing reads cookies and tokens with it. Its docstring states what an
  override must keep: one secret in every worker, and a secret that changes ends every open session.
- SimpleServer.get_session_cookie_name() names the session cookie (default: the same key).
- mcp_server_name: the name the MCP endpoint lists itself under; verify-time normalization strips its namespace.
- mcp_bearer_token: tokens ride as Authorization: Bearer, tools/list needs one and lists only the session's tools,
  a tool outside the grant is an unknown tool, and errors name no framework.
- Both options are refused without expose_tools_over_mcp, and a name outside MCP's tool-name alphabet is refused.
  A single_agent_turn pairing refuses to grant two MCP endpoints listed under one name.

Signed-off-by: Daniele Molinari <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(server_runtime): honor mcp_server_name end to end and refuse bearer tokens without a secret

Review fixes for the MCP endpoint options.

- mcp_server_name is also checked against the name pattern of an MCP grant (MCP_TOOL_ACCESS_NAME_PATTERN in
  tool_access, which MCPToolAccess uses), so a name that an Environment Server cannot grant, one that starts with
  '_' or '-', is refused at config instead of failing every episode before the agent seed. The grant contract is
  unchanged. A dot stays refused: Pi's MCP adapter and Codex refuse server names outside [A-Za-z0-9_-].
- seed_mcp_servers keys each entry by the seed metadata's server_name, else the server's name, and refuses two
  servers listed under one name. URLs, headers and routing still use the server's reference. The sandboxed
  OpenCode agent's required-server list uses the same keys; the sandboxed Pi agent reads them as given.
- An MCP endpoint with mcp_bearer_token refuses to start while get_session_secret() is the public session
  middleware key, since code that reads one bearer token could sign another session's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* revert(agents): keep MCP endpoint names off the legacy seeder

Review asked to keep the MCP changes on the agent-session path. The only callers of
seed_mcp_servers, the sandboxed Pi and OpenCode agents, run on the agent-owned /run path
that NVIDIA-NeMo#5222 deprecates, and OfficeEnv's Pi preset gets the advertised name and headers
through its MCPToolAccess grant. The seeder keys its entries by server name again, and
the aliasing's tests go with it. It no longer refuses two servers under one name, a
refusal that came after the primary server may have started a task sandbox and before
OpenCode's cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(opencode_agent): refuse MCP grants whose tools OpenCode could name alike

Review found that distinct endpoint names can still hide a tool in opencode_agent.
OpenCode keys each MCP tool <grant>_<tool>, writing characters outside [a-zA-Z0-9_-]
as '_', and a later tool under a key already taken replaces the earlier one without a
word: `company` serving `files_list` and `company_files` serving `list` both register
`company_files_list`. The agent's seed now refuses two MCP grants whose tools could
share a key, which the grant names decide: equal once written as OpenCode writes them,
or one the other followed by '_'. single_agent_turn's README and check, and the
mcp_server_name field, describe tool naming as each harness's own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(server_runtime): sign sessions with a secret made for the run

Review asked for per-run session secrets in server_runtime, as episode_token_secret()
does (NVIDIA-NeMo#5346), instead of each server overriding get_session_secret().
run_session_secret(name) makes one secret per server for the run and keeps it in the
environment, so the workers uvicorn starts after the main process built the server
inherit it. get_session_secret() returns it when the server sets
signs_sessions_with_run_secret or its config sets mcp_bearer_token, so bearer tokens work
from YAML alone and with any number of workers; otherwise it is the public key, as before.
The session_secret property resolves it once per server (a cached_property, so it holds
for a server built without its model_post_init too), and the session middleware, session
routing and the MCP endpoint all read it there, so an override that answers differently
from call to call cannot split them. Exposure still refuses bearer tokens signed with the
public key, which only an override can now produce.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

---------

Signed-off-by: Daniele Molinari <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: yaoyu-33 <[email protected]>
yaoyu-33 added a commit to yaoyu-33/Gym that referenced this pull request Dec 1, 2026
…ion to keep the recorded history (NVIDIA-NeMo#6672)

* feat(core): session secrets, cookie names and MCP endpoint options for servers that sandboxed code calls

A resources server that lends a sandbox is reached by code the model controls, so the session key that every
caller can compute from the server's class and name must not sign its cookies and MCP tokens, and its endpoint
should look like an ordinary one.

- SimpleServer.get_session_secret() signs session cookies and MCP session tokens (default: the session middleware
  key, so nothing changes). Session routing reads cookies and tokens with it. Its docstring states what an
  override must keep: one secret in every worker, and a secret that changes ends every open session.
- SimpleServer.get_session_cookie_name() names the session cookie (default: the same key).
- mcp_server_name: the name the MCP endpoint lists itself under; verify-time normalization strips its namespace.
- mcp_bearer_token: tokens ride as Authorization: Bearer, tools/list needs one and lists only the session's tools,
  a tool outside the grant is an unknown tool, and errors name no framework.
- Both options are refused without expose_tools_over_mcp, and a name outside MCP's tool-name alphabet is refused.
  A single_agent_turn pairing refuses to grant two MCP endpoints listed under one name.

Signed-off-by: Daniele Molinari <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(server_runtime): honor mcp_server_name end to end and refuse bearer tokens without a secret

Review fixes for the MCP endpoint options.

- mcp_server_name is also checked against the name pattern of an MCP grant (MCP_TOOL_ACCESS_NAME_PATTERN in
  tool_access, which MCPToolAccess uses), so a name that an Environment Server cannot grant, one that starts with
  '_' or '-', is refused at config instead of failing every episode before the agent seed. The grant contract is
  unchanged. A dot stays refused: Pi's MCP adapter and Codex refuse server names outside [A-Za-z0-9_-].
- seed_mcp_servers keys each entry by the seed metadata's server_name, else the server's name, and refuses two
  servers listed under one name. URLs, headers and routing still use the server's reference. The sandboxed
  OpenCode agent's required-server list uses the same keys; the sandboxed Pi agent reads them as given.
- An MCP endpoint with mcp_bearer_token refuses to start while get_session_secret() is the public session
  middleware key, since code that reads one bearer token could sign another session's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* revert(agents): keep MCP endpoint names off the legacy seeder

Review asked to keep the MCP changes on the agent-session path. The only callers of
seed_mcp_servers, the sandboxed Pi and OpenCode agents, run on the agent-owned /run path
that #5222 deprecates, and OfficeEnv's Pi preset gets the advertised name and headers
through its MCPToolAccess grant. The seeder keys its entries by server name again, and
the aliasing's tests go with it. It no longer refuses two servers under one name, a
refusal that came after the primary server may have started a task sandbox and before
OpenCode's cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(opencode_agent): refuse MCP grants whose tools OpenCode could name alike

Review found that distinct endpoint names can still hide a tool in opencode_agent.
OpenCode keys each MCP tool <grant>_<tool>, writing characters outside [a-zA-Z0-9_-]
as '_', and a later tool under a key already taken replaces the earlier one without a
word: `company` serving `files_list` and `company_files` serving `list` both register
`company_files_list`. The agent's seed now refuses two MCP grants whose tools could
share a key, which the grant names decide: equal once written as OpenCode writes them,
or one the other followed by '_'. single_agent_turn's README and check, and the
mcp_server_name field, describe tool naming as each harness's own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(server_runtime): sign sessions with a secret made for the run

Review asked for per-run session secrets in server_runtime, as episode_token_secret()
does (#5346), instead of each server overriding get_session_secret().
run_session_secret(name) makes one secret per server for the run and keeps it in the
environment, so the workers uvicorn starts after the main process built the server
inherit it. get_session_secret() returns it when the server sets
signs_sessions_with_run_secret or its config sets mcp_bearer_token, so bearer tokens work
from YAML alone and with any number of workers; otherwise it is the public key, as before.
The session_secret property resolves it once per server (a cached_property, so it holds
for a server built without its model_post_init too), and the session middleware, session
routing and the MCP endpoint all read it there, so an override that answers differently
from call to call cannot split them. Exposure still refuses bearer tokens signed with the
public key, which only an override can now produce.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(single_agent_turn): drive the agent one step at a time and end the episode on the task state

A resources server whose task ends through its state, rather than through one tool's call, can now have its
episode end right after the step that ended the task. OfficeEnv's task ends when its user app's task row leaves
pending, which several operations reach, depending on how a row exposes its apps.

- single_agent_turn: max_episode_steps drives the agent one step per activation, up to that many steps, and
  end_on_task_state reads the resources session's task state between steps (GET /task_state, ResourcesTaskState
  in nemo_gym.server_runtime). Each step's failure report is kept. The server checks at startup that its agent keeps
  a session, runs the tools it calls and stops after one step. Driven episodes take part in checkpoints as restarts
  (BaseEnvironmentServer.checkpoint_mode_in_effect).
- simple_agent: with x-ng-agent-episode-step-limit, a step stopped by its own one-step limit counts as completed
  unless it is the episode's last, and the session keeps one invocation for the episode, as the agent's own loop
  does, instead of one per step that repeats the whole history.
- OfficeEnv: GET /task_state answers ResourcesTaskState; close_tools_on_task_end refuses the calls a step makes after
  the one that ended its task; its rows route by taskset to single_agent_turn with the step loop on, and the config
  allows only the simple agent. A retired attempt no longer keeps its episode, so its replacement can seed the same
  session ID. The server runs OfficeEnv 1.14.0 (1.13.0 at least), with its example rows emitted again.

Signed-off-by: Daniele Molinari <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(single_agent_turn): run the step loop's tests in the core suite, and keep a simple_agent subclass in step

CI on the step loop found two things:
- agentic_turn_simulation_agent overrides simple_agent's _create_episode, which now takes
  step_limit_owned_by_caller. The override accepts it; only an agent session sets it, and this agent
  refuses those.
- The core coverage gate counts single_agent_turn's and simple_agent's app.py, but the step loop's tests
  ran in the server suite only. They move to the core suite unchanged, and simple_agent's step limit and
  invocation folding get core tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(single_agent_turn): import each name in the moved step-loop tests from the module that defines it

Tests under tests/ import from the defining module, not a package's public API, and
test_the_librarys_tests_import_from_the_module_that_defines_each_name failed on the two files this PR moved
into the core suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(simple_agent): one step per activation that names the episode's step limit, counted by its index

With x-ng-agent-episode-step-limit, the agent takes one step (one model call and the tool calls it makes) whatever
its max_steps says, so a pairing no longer needs max_steps: 1, which composition drops when --agent-type
simple_agent replaces the environment's agent. Requests without the header run as before.

- The step is the activation's index (x-ng-agent-activation), which such a caller sends with every step, not the
  count of requests, so a step resent after a dropped connection is not counted as the next one.
- The session keeps the model server's cookies from step to step, so the episode keeps one model server session.
- A step that raises ends the episode's folded invocation as failed (or incomplete when cancelled), not with the
  completed status of the step before.
- The step keywords go to _create_episode only with the header, so an override that predates them keeps working;
  agentic_turn_simulation_agent's override no longer needs to accept one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(single_agent_turn): drive only agents that take one step per activation, and keep what the steps did

- STEP_DRIVEN_AGENT_TYPES (nemo_gym.config, beside AGENT_SESSION_AGENT_TYPES) lists the agent types that take one
  step per activation that names the episode's step limit: simple_agent. The startup check refuses any other type,
  such as hermes_agent or browsecomp_agent, which keep a session but run their own loop in an activation; a unit
  test keeps the list in step with the agent apps. The check no longer reads max_steps, and reads execute_tools as
  the agent's config does, so a string "false" is false.
- A failure after a step completed keeps the completed steps, their output and summed usage, as its partial
  response, unless it already carries one; a failure before the first reply has none.
- An episode that runs out of steps with every step calling a tool says so in its reply's metadata
  (ng_termination_reason: max_episode_steps). Its status stays the last step's: incomplete_details names only the
  model's own cutoffs, and an incomplete reply would read as malformed to rollout recovery.
- The task state is not read after the last step, which ends the episode either way.
- GET /task_state answering 404 with failure_kind session_lost ends the episode, which goes on to /verify and its
  masked lost-session result, as when a tool call finds the session gone. Other failed reads fail the episode as
  before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(server_runtime): an environment server's checkpoint mode in effect sets its participant and its episodes

A server whose class declares exported but whose instance runs as restart_only installs a restart_only participant,
and its episodes begin as restarts; an unknown mode in effect stops the server at setup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv): run on single_agent_turn_legacy, so flat rows and session-less agents run too

single_agent_turn's /run takes only episode requests, so flat rows (training corpora, rows routed by their agent)
failed. single_agent_turn_legacy takes flat rows and taskset episodes, and runs the same step loop: OfficeEnv keeps
max_episode_steps 50, end_on_task_state, direct HTTP tools and the example taskset's route, and the simple agent no
longer sets max_steps: 1. Composition's fallback relays an agent without agent sessions through legacy_agent to its
own /run, so allowed_agents also admits simple_agent_with_compaction; the relay takes flat rows, not the taskset's
episodes.

The test that restated the YAML (skipped in CI with OfficeEnv absent) gives way to core tests that resolve the
config with a model and build its environment server: as shipped, with simple_agent.yaml added as --agent-type
simple_agent does, and with the compaction agent's config, where the server becomes a legacy_agent relay. The config
comment and README say what --agent-type and allowed_agents do, and that rollout_recovery.target_level: sibling
applies to the whole training run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* docs: GET /task_state and the episode step-limit header

The Seed/Verify Protocol Extensions table lists GET /task_state, its reply, and what a 404 or 5xx does to the
episode. The agent integration page describes x-ng-agent-episode-step-limit beside x-ng-agent-activation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(single_agent_turn): stop an agent's own loop once its task has ended

With end_on_task_state and no max_episode_steps, single_agent_turn now ends an
agent that runs its own loop (a sandboxed harness) at its task's end, as the
step loop ends a step-driven one:

- Before the agent runs it reads GET /task_state?watch=true; while the agent
  runs it reads again, each read waiting up to 30 s (wait_s).
- Once the task has ended it stops the run with POST /rollouts/{id}/stop
  {"reason": "task_ended", "completed": true}, waits for the activation to
  answer (at most 120 s), then posts /task_state/release.
- The resources server holds its answer to the call that ended the task until
  that release, so the harness never reads it while its run could go on, and
  no model call follows the call that ended the task.
- The server refuses at startup an agent type outside ROLLOUT_STOP_AGENT_TYPES
  (the agents whose runs the stop route can end; a unit test keeps the list in
  step with the apps).

Core: RolloutStopRequest.completed; such a stop answers as completed
(report_rollout_stop) and says so in ng_rollout_stop. Docker uploads take a
bound of their own, so a stop's marker never waits for the exec slot a running
harness holds (uploads_independent_of_execs).

OfficeEnv: GET /task_state takes watch and wait_s (at most 60 s); POST
/task_state/release; task_end_hold_seconds (180) bounds the hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(cline_agent): the fake sandbox session carries expire_completed

report_rollout_stop now reads SandboxSession.expire_completed (a run stopped once
its task has ended answers as completed), so the stand-in that Cline's session
tests use carries it too, as the real session does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv): refuse a tool call after the task ended with ResourcesSessionConflictError

Main's session contract (#5691) has every 409 a resources server answers raise
ResourcesSessionConflictError, and tests/unit_tests/test_session_contract_repo.py
checks it. With close_tools_on_task_end, the OfficeEnv server refused a call after the
task ended with a plain HTTPException(409); it now raises the named error. The status
and the detail are the same, so callers see no change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(core): LentSandboxes lends a sandbox with its own image, environment and setup, and releases all within a deadline

What the OfficeEnv sandboxed server needs from core's lent sandboxes, so it builds on them instead of a copy:

- lend() takes a per-sandbox image, more environment variables and a setup that runs against the started sandbox,
  its files delivered, before it is lent (start_with_setup); a setup that fails stops the sandbox.
- The start runs to its end once begun, within start_timeout_s (30 minutes by default), even while the request that
  asked for it is cancelled: a create cut in flight leaves a sandbox whose id the provider never returned. A lend
  cancelled meanwhile lends nothing and stops what it started, and says so in the log.
- release_all(timeout_s=...) refuses new lends (503) from its start, waits for those still starting, stops everything
  within the deadline, and returns and logs the sessions whose sandbox may still run, for a reaper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv): run OfficeEnv episodes in a sandbox, for Gym's sandboxed harnesses

resources_servers/officeenv_sandbox's OfficeEnvSandboxResourcesServer subclasses the OfficeEnv server and lends each
episode session a sandbox through LentSandboxes (an operate descriptor: the harness uses it, only the server stops
it), stopped before the episode is graded.

- The harness reaches the apps as the row's exposure says: MCP tools, a command per app (cli), or endpoints it finds
  over MCP and calls with curl (api_search).
- File content stays out of the conversation through OfficeEnv's workspace mode: downloads land in the workspace,
  uploads and attachments name a workspace file, and a file API moves bytes directly.
- The sandbox sees an ordinary company API. Only Gym's servers on this node (any of the node's own addresses) and
  trusted_networks reach seeding, closing, verification, metrics, the reverify mode, the app catalog, the task state
  and the tool routes, which answer others 404 before reading a body; sessions are signed with a per-process secret.
- Seeds take turns, and a seed is admitted again before it lends; a close or a retire stops the sandbox, a failed
  seed's stop is tried again at its session's close, and shutdown stops everything within the run's grace.
- A sandbox provider failure fails the call (502) and masks the episode's reward.
- Configs for Pi (Docker and OpenSandbox), Codex CLI, mini-SWE, OpenCode, OpenClaw and Terminus 2; nine sandbox tasks
  (OfficeEnv 1.14.0), the first five as example rows with Pi's rollouts of them; images and a README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(core): LentSandboxes logs a start its limit cut before the provider returned the sandbox's id

When start_timeout_s cuts a provider's create in flight, the sandbox's id is unknown, so the lend's stop cannot reach
what the create left. The lend now logs that cut at ERROR with the resources session, the task (id and taskset), the
provider, the image and the labels, so a reaper can find the sandbox. A start cut after the create returned stops its
sandbox as before and asks for no reaper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* refactor(officeenv_sandbox): name each harness's instances after it, so harness configs compose in one run

Every harness config defined `oe` and `single_agent_turn_legacy`, so two of them could not run together. Now:

- the episodes' resources server is officeenv_sandbox_resources_server;
- each config adds officeenv_sandbox_<harness>_agent (`_inherit_from` Gym's instance of the harness, as benchmarks do)
  and officeenv_sandbox_<harness>_environment_server (`_inherit_from: single_agent_turn_legacy`);
- Pi, Codex and OpenCode, which name MCP tools their own way, run on their own copy of the episodes' server
  (officeenv_sandbox_<harness>_resources_server, `_copy` with its mcp_tool_prefix); the other harnesses run on the
  shared one. A copy takes the shared server's settings from the merged config, so one override reaches every harness.

The interpolations, the documented overrides, the probe script and the README follow (a table of the names; the
OpenSandbox config is listed after the other harness configs, since a later one pulls the episodes' config in again).
A core test resolves each config alone and all six together with a model config, and replaces the server test that
restated their YAML; it needs no OfficeEnv, so it runs in CI. The OpenCode and OpenClaw configs and the README no
longer say those harnesses refuse MCP tool grants.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv_sandbox): sandbox_config.start_timeout_s bounds a sandbox's start; host_relay needs trusted_workstation

- sandbox_config.start_timeout_s (1800 s by default, a finite number above 0) is passed to LentSandboxes, which fails
  the seed at that limit and logs a create it cut for a reaper. The README says when to raise it: creates on a busy
  OpenSandbox cell have taken up to 2,430 s.
- host_relay forwards sandbox connections from the host's loopback, which the caller check takes for Gym's own
  servers, so code in a sandbox could call the routes kept for Gym for any session. Config validation now refuses
  host_relay unless sandbox_config.trusted_workstation is true, which a config sets only on a single-user workstation;
  its description and the README state the risk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv_sandbox): officeenv_sandboxless.yaml runs the OfficeEnv server's instances under names of their own

It composes resources_servers/officeenv/configs/officeenv.yaml and copies (`_copy`) its three instances as
officeenv_sandboxless_resources_server, officeenv_sandbox_simple_agent and officeenv_sandbox_environment_server, each
copy pointing at the other copies, while the OfficeEnv server's instances keep their names. The copied agent declares
no dataset, so the example rows and their taskset stay with the OfficeEnv server's instances, and rows that name
officeenv_sandbox_simple_agent (flat rows, agent_ref) route to the copied environment server.

A `_copy` takes its source as written, before the source's own `_inherit_from` applies, so the environment server is
copied as the instance of the server type officeenv_environment_server inherits, with that server's own settings for
it on top. The core test checks each copy against its source, references aside, alone and beside the Pi and Codex
configs, so a change to the source's server type fails it rather than leaving the copy behind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv_sandbox): the sandboxless arm copies single_agent_turn_legacy, which the OfficeEnv server now runs

officeenv_environment_server inherits single_agent_turn_legacy now, so the copy takes that instance, then the server's
own settings for it under that type, with its references still pointing at the other copies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* refactor(officeenv_sandbox): every harness runs the episodes' server under its own name, so none is left idle

Each harness config now adds officeenv_sandbox_<harness>_resources_server with `_inherit_from:
officeenv_sandbox_resources_server`, OpenClaw, mini-SWE and Terminus 2 included, and no harness names the episodes'
server. `_inherit_from` reads it from the merged config and takes it out of the run, so a run of one or several
harness configs starts no idle episodes' server, while the episodes config alone still runs it under its own name.
Settings on the episodes' server, the OpenSandbox config's included, reach every harness's server. The OpenSandbox
config still goes after the other harness configs (the first harness config listed pulls the episodes' config in),
and the README now says why. The core test checks that no episodes' server starts or is named beside the harnesses',
alone and with all six, and that the episodes config runs on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(core): the cut-start log says OpenSandbox deletes what an abandoned create left

Main's OpenSandbox provider now deletes the sandbox of a create its caller gave up on (#4799), so
a start that LentSandboxes' start_timeout_s cuts before the provider returned the sandbox's id no
longer needs a reaper there. The ERROR log, LentSandboxes' docstring and the officeenv_sandbox
README now say so, and keep the reaper for providers without that cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv_sandbox): Pi's run ends once its task has ended, on every exposure

- The sandboxed server holds the call that ends a watched episode's task, on
  every way in (tools, commands, endpoints, the file API), until the
  environment server releases it; the episode's lock is let go first. Only
  Gym's node reaches GET /task_state and POST /task_state/release.
- Pi supports POST /rollouts/{rollout_id}/stop (_rollout_sandbox_session): a
  run stopped as completed answers so, marked in ng_rollout_stop, and is not
  reported as a wall-time timeout.
- The Pi config sets end_on_task_state on its environment server and drops
  finish_tool_names (now []): the stop ends the run on cli and api_search rows
  too, which offer no finish tool. Its comment no longer asks cli rows to drop
  the MCP transport, which they run with as it is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* docs(officeenv): the servers run OfficeEnv 1.14.2

1.14.2 is the OfficeEnv release N4's training runs grade with. 1.14.1 and
1.14.2 are patch releases; neither changes the API these servers use. The
READMEs' install lines name it, and the example rows are emitted again by it
(officeenv emit for resources_servers/officeenv, sandbox/prepare_rows.py for
officeenv_sandbox), which changed only their version stamp. The example
rollouts stay the ones collected against 1.14.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv_sandbox): refuse calls after the task ended with ResourcesSessionConflictError

Main's session contract (#5691) has every 409 a resources server answers raise
ResourcesSessionConflictError, and tests/unit_tests/test_session_contract_repo.py
checks it. The sandboxed server refused a tool call once verification began, and a
file API call once the episode's files closed, with plain HTTPException(409)s; both
now raise the named error. The status and the detail are the same, so callers see no
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(core): LentSandboxes shields a start only with start_timeout_s

Main's opencode_search (#6211) lends through LentSandboxes and expects a seed cancelled
while its sandbox starts to stop that sandbox at once, as LentSandboxes did before this
branch; the shielded start made it wait for the start's end. The shield is now opt-in.
Without start_timeout_s a cancel cuts the start as it cuts any await, as on main, and the
lend stops the sandbox it began. With it, the start runs to its end within that limit,
which the OfficeEnv sandbox server sets (sandbox_config.start_timeout_s, 1,800 s by
default). START_TIMEOUT_S goes, since no default limit remains.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* build(officeenv_sandbox): lock against main's upgraded dependency locks

Main's lock upgrade (#6528) moved the root lock, and `uv sync --locked` refused the
sandboxed server's older lock, so neither its suite nor a run could start it. `uv lock`
with uv 0.13.4 takes the root lock's versions (e2b 2.50.0, protobuf-py 0.1.1, pyqwest
0.10.0), keeps the tzdata OfficeEnv pins (2026.6), and passes scripts/component_locks.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(core): a cut start's test counts the closes the provider made

Main's #6410 changed the stopped fixture from AsyncSandbox.stop calls to the closes the
provider made. A start cut before the provider returned its sandbox's id leaves nothing
to close, so the hung-start test now expects none, as the ERROR line it checks says.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(officeenv_sandbox): the stand-in sandbox stops as main's AsyncSandbox.stop does

Main's #6410 moved the shielded, bounded stop into AsyncSandbox.stop(timeout_s=...),
which LentSandboxes now calls. The tests' FakeSandbox.stop took no timeout_s and had no
shield, so a seed or close cancelled during a stop failed or hung. FakeSandbox.stop now
takes timeout_s and shields its provider-side _stop, as AsyncSandbox.stop does, and the
tests that slow down, refuse or hang a stop patch _stop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* refactor(officeenv_sandbox): sign sessions with Gym's run secret

#6161 now makes a secret per server and run in server_runtime, which every worker of the
server shares (signs_sessions_with_run_secret). The sandboxed server sets that flag instead
of minting its own secret in model_post_init and overriding get_session_secret(): its
cookies and MCP tokens are signed, as before, with a secret code in a sandbox cannot
derive from the server's name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(stirrup_agent): stop a run once its task has ended, and run Stirrup on OfficeEnv's sandboxed episodes

Stirrup could not be stopped in flight, so single_agent_turn's end_on_task_state refused it and OfficeEnv's
sandboxed episodes had no Stirrup harness:

- stirrup_agent returns its sandbox session for a rollout stop (_rollout_sandbox_session) and marks the run a
  stop ended (report_rollout_stop): a stop once the task has ended answers as completed, with ng_rollout_stop and
  without the deadline's stop_reason. stirrup_agent joins ROLLOUT_STOP_AGENT_TYPES.
- The runner, ended by its supervisor while a turn's tool calls run, reports that turn's reply too (its calls
  without answers) rather than the history as of the turn's start. A stop once the task has ended lands so: the
  call that ended the task waits for its answer until the run is over, and it stays the run's last item, as Pi's
  does.
- resources_servers/officeenv_sandbox/configs/officeenv_sandbox_stirrup.yaml: Stirrup on `cli` rows, under the
  harness configs' names (officeenv_sandbox_stirrup_agent, _environment_server, _resources_server), no MCP
  transports, end_on_task_state, admitted episodes capped at Stirrup's concurrency.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(stirrup_agent): options to keep the run's history as it was recorded

Training on recorded tokens needs one unbroken history per episode, and Stirrup's defaults rewrite it: past 0.7 of
the context window it replaces the history with a summary, and on a context overflow it unwinds completed turns.
Two options keep those defaults and let a training config turn them off:

- context_summarization_cutoff (default 0.7, Stirrup's): None never summarizes, so an episode at the context limit
  ends there;
- recover_from_context_overflow (default true, Stirrup's): false raises instead of unwinding.

The runner passes them to Stirrup's agent; a payload without them keeps Stirrup's defaults.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* test(officeenv_sandbox): cover the Stirrup harness config in the core config tests

The server's own config tests skip without OfficeEnv, and CI does not install OfficeEnv. The core config tests
resolve each harness config without it, so they now include officeenv_sandbox_stirrup.yaml. The tests make sure
that its instances carry Stirrup's name, that it composes beside the other harness configs with its own cap of 32,
and that its environment server stops the run once the task has ended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* docs(stirrup_agent): describe rollout stops and the history options

The README now says how a rollout stop ends a Stirrup run and what the response carries. A run that ends while a
turn's tool calls run ends with that turn's reply. The options table lists context_summarization_cutoff and
recover_from_context_overflow, and a new section names the settings that keep the recorded history for training.

With context_overflow_recovery off, its default, the client never reports an overflow to Stirrup. So
recover_from_context_overflow changes a run only when a config also turns context_overflow_recovery on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(stirrup_agent): keep a compaction summary out of a stopped run's output

The runner kept the last reply of every model call, a compaction summary's included. A summary can carry tool
calls, since its first attempts offer the tools. If the run then ended while the next policy call waited for the
model, the runner added the summary and its calls to the output as the running turn, although those calls never ran.

The runner now keeps only the reply of the policy turn that is running. Each model call clears the reply first, and
a reply made during a compaction is never kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(stirrup_agent): answer a stop that arrives before the runner starts

A rollout stop accepted during the seed or before the activation keeps the supervisor from launching the runner.
The runner then writes no output.json, so the activation failed with "Stirrup sandbox runner exited without
output", although the agent server had answered the stop as stopped.

When the session reports an expiry before launch, the runner's report is now an empty run that ended at its time
limit, with the session's cookies. The agent server then marks the stop and gives the status the stop asked for, as
for a run that a stop ended. Missing output from a runner that did launch still fails the activation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(stirrup_agent): report the live turn of a run stopped around a compaction

The previous commit kept no summary reply, but a run cut during a compaction still lost its last turn. Stirrup takes
its history snapshot at the start of each turn and summarizes after the turn has answered. So during a summary
request, the snapshot does not hold the turn that just ran, and the output was empty or ended with that turn's call
without its answer.

The runner now watches Stirrup's step, as it watches summarize_messages. It keeps the message list that step gets,
which Stirrup extends with the answered turn, and keeps a reply only when its request is that list and only while
step runs. On a cut, it reports that live list and the running turn's reply. A summary request sends a new list, so
its reply is never kept. The test covers a cut after a summary, in the second summary attempt and in the first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(stirrup_agent): answer a stop that ends the runner while it starts

The runner installs its SIGTERM handler only after its imports. A rollout stop in that window ends the runner
before it writes its report, and the activation still failed with "Stirrup sandbox runner exited without output".

collect now also returns the empty stopped report when the session expired (a stop that the supervisor acted on)
and the runner left no output file. A runner that crashed, or a deadline that ended it with no stop, still fails
the activation. The report helper is now _stopped_without_output, since it covers both windows.

Tests: a stop after the seed and before the run answers as an empty stopped run with no observation gaps. A runner
that never gets past its start answers as an empty stopped run when a stop ended it, and fails when its deadline
did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* refactor(stirrup_agent): drop recover_from_context_overflow

Stirrup reads this option only when the client raises ContextOverflowError, and the client raises it only with
context_overflow_recovery on. With that option off, its default, Stirrup drops no turn whatever this option says.
With it on and this option false, the episode ends at the first overflow, as it does with context_overflow_recovery
off. So the option added no behavior, and a training config needs only context_summarization_cutoff: null.

This removes the field, its payload key, the runner argument, its README row and paragraph, and its test cases.
Draft #5835 adds the same option. No release has it, so no removed-option entry is needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(stirrup_agent): bound context_summarization_cutoff at 1

Stirrup compares the cutoff with the last call's tokens divided by the context window, and it does not reject a
value above 1. Such a value fires only when one call uses more tokens than the window. So a percent such as 70
turned compaction off with no error. The field now accepts values above 0 and at most 1, and null still never
summarizes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* docs(stirrup_agent): name the other history rewrites, and fix the Stirrup config's network note

The Stirrup README section on keeping the recorded history now also names truncation_recovery, which sends one call
with an instruction that the history never records. It also names the two rewrites that stay: an assistant turn
with no parsed tool call loses its tool-call text, and reasoning that comes back in its own field is not sent back.

The header of officeenv_sandbox_stirrup.yaml said that Stirrup's sandboxes need the package index. The agent server
builds Stirrup's Python runtime on its own host and uploads it, so the sandboxes need no internet. Only the host
needs the package index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(single_agent_turn): drive the agent one step at a time and end the episode on the task state

A resources server whose task ends through its state, rather than through one tool's call, can now have its
episode end right after the step that ended the task. OfficeEnv's task ends when its user app's task row leaves
pending, which several operations reach, depending on how a row exposes its apps.

- single_agent_turn: max_episode_steps drives the agent one step per activation, up to that many steps, and
  end_on_task_state reads the resources session's task state between steps (GET /task_state, ResourcesTaskState
  in nemo_gym.server_runtime). Each step's failure report is kept. The server checks at startup that its agent keeps
  a session, runs the tools it calls and stops after one step. Driven episodes take part in checkpoints as restarts
  (BaseEnvironmentServer.checkpoint_mode_in_effect).
- simple_agent: with x-ng-agent-episode-step-limit, a step stopped by its own one-step limit counts as completed
  unless it is the episode's last, and the session keeps one invocation for the episode, as the agent's own loop
  does, instead of one per step that repeats the whole history.
- OfficeEnv: GET /task_state answers ResourcesTaskState; close_tools_on_task_end refuses the calls a step makes after
  the one that ended its task; its rows route by taskset to single_agent_turn with the step loop on, and the config
  allows only the simple agent. A retired attempt no longer keeps its episode, so its replacement can seed the same
  session ID. The server runs OfficeEnv 1.14.0 (1.13.0 at least), with its example rows emitted again.

Signed-off-by: Daniele Molinari <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(single_agent_turn): run the step loop's tests in the core suite, and keep a simple_agent subclass in step

CI on the step loop found two things:
- agentic_turn_simulation_agent overrides simple_agent's _create_episode, which now takes
  step_limit_owned_by_caller. The override accepts it; only an agent session sets it, and this agent
  refuses those.
- The core coverage gate counts single_agent_turn's and simple_agent's app.py, but the step loop's tests
  ran in the server suite only. They move to the core suite unchanged, and simple_agent's step limit and
  invocation folding get core tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(single_agent_turn): import each name in the moved step-loop tests from the module that defines it

Tests under tests/ import from the defining module, not a package's public API, and
test_the_librarys_tests_import_from_the_module_that_defines_each_name failed on the two files this PR moved
into the core suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(simple_agent): one step per activation that names the episode's step limit, counted by its index

With x-ng-agent-episode-step-limit, the agent takes one step (one model call and the tool calls it makes) whatever
its max_steps says, so a pairing no longer needs max_steps: 1, which composition drops when --agent-type
simple_agent replaces the environment's agent. Requests without the header run as before.

- The step is the activation's index (x-ng-agent-activation), which such a caller sends with every step, not the
  count of requests, so a step resent after a dropped connection is not counted as the next one.
- The session keeps the model server's cookies from step to step, so the episode keeps one model server session.
- A step that raises ends the episode's folded invocation as failed (or incomplete when cancelled), not with the
  completed status of the step before.
- The step keywords go to _create_episode only with the header, so an override that predates them keeps working;
  agentic_turn_simulation_agent's override no longer needs to accept one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(single_agent_turn): drive only agents that take one step per activation, and keep what the steps did

- STEP_DRIVEN_AGENT_TYPES (nemo_gym.config, beside AGENT_SESSION_AGENT_TYPES) lists the agent types that take one
  step per activation that names the episode's step limit: simple_agent. The startup check refuses any other type,
  such as hermes_agent or browsecomp_agent, which keep a session but run their own loop in an activation; a unit
  test keeps the list in step with the agent apps. The check no longer reads max_steps, and reads execute_tools as
  the agent's config does, so a string "false" is false.
- A failure after a step completed keeps the completed steps, their output and summed usage, as its partial
  response, unless it already carries one; a failure before the first reply has none.
- An episode that runs out of steps with every step calling a tool says so in its reply's metadata
  (ng_termination_reason: max_episode_steps). Its status stays the last step's: incomplete_details names only the
  model's own cutoffs, and an incomplete reply would read as malformed to rollout recovery.
- The task state is not read after the last step, which ends the episode either way.
- GET /task_state answering 404 with failure_kind session_lost ends the episode, which goes on to /verify and its
  masked lost-session result, as when a tool call finds the session gone. Other failed reads fail the episode as
  before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(server_runtime): an environment server's checkpoint mode in effect sets its participant and its episodes

A server whose class declares exported but whose instance runs as restart_only installs a restart_only participant,
and its episodes begin as restarts; an unknown mode in effect stops the server at setup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv): run on single_agent_turn_legacy, so flat rows and session-less agents run too

single_agent_turn's /run takes only episode requests, so flat rows (training corpora, rows routed by their agent)
failed. single_agent_turn_legacy takes flat rows and taskset episodes, and runs the same step loop: OfficeEnv keeps
max_episode_steps 50, end_on_task_state, direct HTTP tools and the example taskset's route, and the simple agent no
longer sets max_steps: 1. Composition's fallback relays an agent without agent sessions through legacy_agent to its
own /run, so allowed_agents also admits simple_agent_with_compaction; the relay takes flat rows, not the taskset's
episodes.

The test that restated the YAML (skipped in CI with OfficeEnv absent) gives way to core tests that resolve the
config with a model and build its environment server: as shipped, with simple_agent.yaml added as --agent-type
simple_agent does, and with the compaction agent's config, where the server becomes a legacy_agent relay. The config
comment and README say what --agent-type and allowed_agents do, and that rollout_recovery.target_level: sibling
applies to the whole training run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* docs: GET /task_state and the episode step-limit header

The Seed/Verify Protocol Extensions table lists GET /task_state, its reply, and what a 404 or 5xx does to the
episode. The agent integration page describes x-ng-agent-episode-step-limit beside x-ng-agent-activation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(core): LentSandboxes lends a sandbox with its own image, environment and setup, and releases all within a deadline

What the OfficeEnv sandboxed server needs from core's lent sandboxes, so it builds on them instead of a copy:

- lend() takes a per-sandbox image, more environment variables and a setup that runs against the started sandbox,
  its files delivered, before it is lent (start_with_setup); a setup that fails stops the sandbox.
- The start runs to its end once begun, within start_timeout_s (30 minutes by default), even while the request that
  asked for it is cancelled: a create cut in flight leaves a sandbox whose id the provider never returned. A lend
  cancelled meanwhile lends nothing and stops what it started, and says so in the log.
- release_all(timeout_s=...) refuses new lends (503) from its start, waits for those still starting, stops everything
  within the deadline, and returns and logs the sessions whose sandbox may still run, for a reaper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv): run OfficeEnv episodes in a sandbox, for Gym's sandboxed harnesses

resources_servers/officeenv_sandbox's OfficeEnvSandboxResourcesServer subclasses the OfficeEnv server and lends each
episode session a sandbox through LentSandboxes (an operate descriptor: the harness uses it, only the server stops
it), stopped before the episode is graded.

- The harness reaches the apps as the row's exposure says: MCP tools, a command per app (cli), or endpoints it finds
  over MCP and calls with curl (api_search).
- File content stays out of the conversation through OfficeEnv's workspace mode: downloads land in the workspace,
  uploads and attachments name a workspace file, and a file API moves bytes directly.
- The sandbox sees an ordinary company API. Only Gym's servers on this node (any of the node's own addresses) and
  trusted_networks reach seeding, closing, verification, metrics, the reverify mode, the app catalog, the task state
  and the tool routes, which answer others 404 before reading a body; sessions are signed with a per-process secret.
- Seeds take turns, and a seed is admitted again before it lends; a close or a retire stops the sandbox, a failed
  seed's stop is tried again at its session's close, and shutdown stops everything within the run's grace.
- A sandbox provider failure fails the call (502) and masks the episode's reward.
- Configs for Pi (Docker and OpenSandbox), Codex CLI, mini-SWE, OpenCode, OpenClaw and Terminus 2; nine sandbox tasks
  (OfficeEnv 1.14.0), the first five as example rows with Pi's rollouts of them; images and a README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(core): LentSandboxes logs a start its limit cut before the provider returned the sandbox's id

When start_timeout_s cuts a provider's create in flight, the sandbox's id is unknown, so the lend's stop cannot reach
what the create left. The lend now logs that cut at ERROR with the resources session, the task (id and taskset), the
provider, the image and the labels, so a reaper can find the sandbox. A start cut after the create returned stops its
sandbox as before and asks for no reaper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* refactor(officeenv_sandbox): name each harness's instances after it, so harness configs compose in one run

Every harness config defined `oe` and `single_agent_turn_legacy`, so two of them could not run together. Now:

- the episodes' resources server is officeenv_sandbox_resources_server;
- each config adds officeenv_sandbox_<harness>_agent (`_inherit_from` Gym's instance of the harness, as benchmarks do)
  and officeenv_sandbox_<harness>_environment_server (`_inherit_from: single_agent_turn_legacy`);
- Pi, Codex and OpenCode, which name MCP tools their own way, run on their own copy of the episodes' server
  (officeenv_sandbox_<harness>_resources_server, `_copy` with its mcp_tool_prefix); the other harnesses run on the
  shared one. A copy takes the shared server's settings from the merged config, so one override reaches every harness.

The interpolations, the documented overrides, the probe script and the README follow (a table of the names; the
OpenSandbox config is listed after the other harness configs, since a later one pulls the episodes' config in again).
A core test resolves each config alone and all six together with a model config, and replaces the server test that
restated their YAML; it needs no OfficeEnv, so it runs in CI. The OpenCode and OpenClaw configs and the README no
longer say those harnesses refuse MCP tool grants.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv_sandbox): sandbox_config.start_timeout_s bounds a sandbox's start; host_relay needs trusted_workstation

- sandbox_config.start_timeout_s (1800 s by default, a finite number above 0) is passed to LentSandboxes, which fails
  the seed at that limit and logs a create it cut for a reaper. The README says when to raise it: creates on a busy
  OpenSandbox cell have taken up to 2,430 s.
- host_relay forwards sandbox connections from the host's loopback, which the caller check takes for Gym's own
  servers, so code in a sandbox could call the routes kept for Gym for any session. Config validation now refuses
  host_relay unless sandbox_config.trusted_workstation is true, which a config sets only on a single-user workstation;
  its description and the README state the risk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv_sandbox): officeenv_sandboxless.yaml runs the OfficeEnv server's instances under names of their own

It composes resources_servers/officeenv/configs/officeenv.yaml and copies (`_copy`) its three instances as
officeenv_sandboxless_resources_server, officeenv_sandbox_simple_agent and officeenv_sandbox_environment_server, each
copy pointing at the other copies, while the OfficeEnv server's instances keep their names. The copied agent declares
no dataset, so the example rows and their taskset stay with the OfficeEnv server's instances, and rows that name
officeenv_sandbox_simple_agent (flat rows, agent_ref) route to the copied environment server.

A `_copy` takes its source as written, before the source's own `_inherit_from` applies, so the environment server is
copied as the instance of the server type officeenv_environment_server inherits, with that server's own settings for
it on top. The core test checks each copy against its source, references aside, alone and beside the Pi and Codex
configs, so a change to the source's server type fails it rather than leaving the copy behind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv_sandbox): the sandboxless arm copies single_agent_turn_legacy, which the OfficeEnv server now runs

officeenv_environment_server inherits single_agent_turn_legacy now, so the copy takes that instance, then the server's
own settings for it under that type, with its references still pointing at the other copies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* refactor(officeenv_sandbox): every harness runs the episodes' server under its own name, so none is left idle

Each harness config now adds officeenv_sandbox_<harness>_resources_server with `_inherit_from:
officeenv_sandbox_resources_server`, OpenClaw, mini-SWE and Terminus 2 included, and no harness names the episodes'
server. `_inherit_from` reads it from the merged config and takes it out of the run, so a run of one or several
harness configs starts no idle episodes' server, while the episodes config alone still runs it under its own name.
Settings on the episodes' server, the OpenSandbox config's included, reach every harness's server. The OpenSandbox
config still goes after the other harness configs (the first harness config listed pulls the episodes' config in),
and the README now says why. The core test checks that no episodes' server starts or is named beside the harnesses',
alone and with all six, and that the episodes config runs on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(core): the cut-start log says OpenSandbox deletes what an abandoned create left

Main's OpenSandbox provider now deletes the sandbox of a create its caller gave up on (#4799), so
a start that LentSandboxes' start_timeout_s cuts before the provider returned the sandbox's id no
longer needs a reaper there. The ERROR log, LentSandboxes' docstring and the officeenv_sandbox
README now say so, and keep the reaper for providers without that cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(officeenv_sandbox): Pi's run ends once its task has ended, on every exposure

- The sandboxed server holds the call that ends a watched episode's task, on
  every way in (tools, commands, endpoints, the file API), until the
  environment server releases it; the episode's lock is let go first. Only
  Gym's node reaches GET /task_state and POST /task_state/release.
- Pi supports POST /rollouts/{rollout_id}/stop (_rollout_sandbox_session): a
  run stopped as completed answers so, marked in ng_rollout_stop, and is not
  reported as a wall-time timeout.
- The Pi config sets end_on_task_state on its environment server and drops
  finish_tool_names (now []): the stop ends the run on cli and api_search rows
  too, which offer no finish tool. Its comment no longer asks cli rows to drop
  the MCP transport, which they run with as it is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* docs(officeenv): the servers run OfficeEnv 1.14.2

1.14.2 is the OfficeEnv release N4's training runs grade with. 1.14.1 and
1.14.2 are patch releases; neither changes the API these servers use. The
READMEs' install lines name it, and the example rows are emitted again by it
(officeenv emit for resources_servers/officeenv, sandbox/prepare_rows.py for
officeenv_sandbox), which changed only their version stamp. The example
rollouts stay the ones collected against 1.14.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv_sandbox): refuse calls after the task ended with ResourcesSessionConflictError

Main's session contract (#5691) has every 409 a resources server answers raise
ResourcesSessionConflictError, and tests/unit_tests/test_session_contract_repo.py
checks it. The sandboxed server refused a tool call once verification began, and a
file API call once the episode's files closed, with plain HTTPException(409)s; both
now raise the named error. The status and the detail are the same, so callers see no
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(core): LentSandboxes shields a start only with start_timeout_s

Main's opencode_search (#6211) lends through LentSandboxes and expects a seed cancelled
while its sandbox starts to stop that sandbox at once, as LentSandboxes did before this
branch; the shielded start made it wait for the start's end. The shield is now opt-in.
Without start_timeout_s a cancel cuts the start as it cuts any await, as on main, and the
lend stops the sandbox it began. With it, the start runs to its end within that limit,
which the OfficeEnv sandbox server sets (sandbox_config.start_timeout_s, 1,800 s by
default). START_TIMEOUT_S goes, since no default limit remains.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* build(officeenv_sandbox): lock against main's upgraded dependency locks

Main's lock upgrade (#6528) moved the root lock, and `uv sync --locked` refused the
sandboxed server's older lock, so neither its suite nor a run could start it. `uv lock`
with uv 0.13.4 takes the root lock's versions (e2b 2.50.0, protobuf-py 0.1.1, pyqwest
0.10.0), keeps the tzdata OfficeEnv pins (2026.6), and passes scripts/component_locks.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(core): a cut start's test counts the closes the provider made

Main's #6410 changed the stopped fixture from AsyncSandbox.stop calls to the closes the
provider made. A start cut before the provider returned its sandbox's id leaves nothing
to close, so the hung-start test now expects none, as the ERROR line it checks says.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* feat(single_agent_turn): stop an agent's own loop once its task has ended

With end_on_task_state and no max_episode_steps, single_agent_turn now ends an
agent that runs its own loop (a sandboxed harness) at its task's end, as the
step loop ends a step-driven one:

- Before the agent runs it reads GET /task_state?watch=true; while the agent
  runs it reads again, each read waiting up to 30 s (wait_s).
- Once the task has ended it stops the run with POST /rollouts/{id}/stop
  {"reason": "task_ended", "completed": true}, waits for the activation to
  answer (at most 120 s), then posts /task_state/release.
- The resources server holds its answer to the call that ended the task until
  that release, so the harness never reads it while its run could go on, and
  no model call follows the call that ended the task.
- The server refuses at startup an agent type outside ROLLOUT_STOP_AGENT_TYPES
  (the agents whose runs the stop route can end; a unit test keeps the list in
  step with the apps).

Core: RolloutStopRequest.completed; such a stop answers as completed
(report_rollout_stop) and says so in ng_rollout_stop. Docker uploads take a
bound of their own, so a stop's marker never waits for the exec slot a running
harness holds (uploads_independent_of_execs).

OfficeEnv: GET /task_state takes watch and wait_s (at most 60 s); POST
/task_state/release; task_end_hold_seconds (180) bounds the hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(officeenv_sandbox): the stand-in sandbox stops as main's AsyncSandbox.stop does

Main's #6410 moved the shielded, bounded stop into AsyncSandbox.stop(timeout_s=...),
which LentSandboxes now calls. The tests' FakeSandbox.stop took no timeout_s and had no
shield, so a seed or close cancelled during a stop failed or hung. FakeSandbox.stop now
takes timeout_s and shields its provider-side _stop, as AsyncSandbox.stop does, and the
tests that slow down, refuse or hang a stop patch _stop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* test(cline_agent): the fake sandbox session carries expire_completed

report_rollout_stop now reads SandboxSession.expire_completed (a run stopped once
its task has ended answers as completed), so the stand-in that Cline's session
tests use carries it too, as the real session does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* refactor(officeenv_sandbox): sign sessions with Gym's run secret

#6161 now makes a secret per server and run in server_runtime, which every worker of the
server shares (signs_sessions_with_run_secret). The sandboxed server sets that flag instead
of minting its own secret in model_post_init and overriding get_session_secret(): its
cookies and MCP tokens are signed, as before, with a secret code in a sandbox cannot
derive from the server's name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* fix(officeenv): refuse a tool call after the task ended with ResourcesSessionConflictError

Main's session contract (#5691) has every 409 a resources server answers raise
ResourcesSessionConflictError, and tests/unit_tests/test_session_contract_repo.py
checks it. With close_tools_on_task_end, the OfficeEnv server refused a call after the
task ended with a plain HTTPException(409); it now raises the named error. The status
and the detail are the same, so callers see no change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>

* docs(officeenv_sandbox): say when the task-end stop ends a Stirrup run

Stirrup cannot run without a finish tool, so with its default finish tool most runs end when the model calls
finish. The environment server's task-end stop ends a run that calls `user complete-task`, before its next model
call. Pi's config sets finish_tool_names: [], so for Pi the stop is the normal end. The README now says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(core): release_all stops the lent sandboxes while a lend is still starting

release_all waited for every start in flight before it stopped any lent
sandbox, all inside one time limit. One slow start at shutdown then left
every lent sandbox running until its TTL. Now the lent sandboxes stop at
once, and each starting sandbox is stopped when its start ends.

The new test fails before this change (no sandbox stopped) and passes
after it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(officeenv_sandbox): keep the agent and environment servers on 127.0.0.1

NeMo RL sets default_host to the node's address, and an explicit
default_host applies to every server, not only to the types in
absolute_ip_server_types. A sandbox's network rule opens every port of an
allowed host. So code in a sandbox could call the agent and environment
servers: run Pi on Gym's host (/v1/responses without a session), start
episodes (/run) and stop another episode's run
(/rollouts/{rollout_id}/stop).

Each harness config now sets host: 127.0.0.1 on its agent and its
environment server. No sandbox calls them: each harness in a sandbox calls
only the model server and the resources server, and NeMo RL calls /run from
the same node. Without default_host, Gym already binds them to 127.0.0.1.
The comment in officeenv_opensandbox.yaml and the README now say this.

The new config test resolves every harness config under
default_host: 10.0.0…

This branch was previously deployed

1 inactive deployment
public — f81e80a8 Deployed Oct 29, 2026 by copy-pr-bot[bot] via release / finalize / notify #8348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior complexity:low Localized change in one scope with a small, straightforward review surface ready-to-merge PR is approved, current, and waiting for final CI or merge support User questions, support, or maintenance requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants