Skip to content

fix(sandbox): correct E2B sandbox-stop errors and support e2b 2.62 - #5509

Merged
yfw merged 4 commits into
NVIDIA-NeMo:mainfrom
max-sudolabs:fix/e2b-sandbox-errors
Nov 17, 2026
Merged

yfw merged 4 commits into
NVIDIA-NeMo:mainfrom
max-sudolabs:fix/e2b-sandbox-errors

Conversation

@max-sudolabs

Copy link
Copy Markdown
Contributor

What does this PR do?

Three small fixes in the sandbox layer, found while running a Gym environment on E2B with e2b 2.62:

  1. Sync API reported the wrong timeout. The sync wrapper waits on the event loop with future.result(timeout=3600). On Python 3.11+ that TimeoutError is the builtin one, so a TimeoutError raised by the operation itself was relabeled "timed out waiting for the sync loop after 3600s", even when it came 15 s in. The wrapper now re-raises the operation's own error when the future has finished.
  2. A stopped E2B sandbox looked like a command timeout. When a sandbox is killed, paused, or reaches its lifetime (ttl_s) mid-command, e2b 2.62+ raises SandboxNotRunningException. exec now returns error_type="sandbox" (return code 125), as the Docker, Apptainer and OpenShell providers already do, instead of raising TimeoutError. The class is looked up with getattr, so e2b 2.46 still works.
  3. Sandbox creation failed with e2b 2.62 when Gym's aiohttp transport is active. e2b 2.62 calls the transport factory with new http_version and retry_connect keywords, which Gym's replacement factory rejected. The failure happened after E2B had started the sandbox, so it kept running until its timeout. The factory now accepts both; GymAiohttpTransport already makes no connection retries and only speaks HTTP/1.1.

CI pins e2b 2.46.0 in uv.lock, but e2b>=2.46.0,<3.0.0 allows 2.62, so any environment that resolves a newer e2b hit (2) and (3).

Validation

  • New unit tests for each fix; each fails without its fix. Fix (3) is also covered with fake SDK modules, so CI catches it on the pinned 2.46.
  • test_sandbox.py, test_e2b_provider.py, test_e2b_sdk_transport_fallback.py: 203 passed with e2b 2.46.0 and with 2.62.0.
  • pre-commit run --all-files: passed.

Rollouts

N/A for model rollouts (no agent or verifier change). Checked against hosted E2B with e2b 2.62:

Scenario main This branch
ttl_s=15, sleep 60 via the sync API "timed out waiting for the sync loop after 3600s" after 15 s error_type="sandbox", status stopped
Sandbox create with Gym's aiohttp transport E2BCreateError ... unexpected keyword argument 'retry_connect', sandbox left running create, upload/download, exec, stop() work

Compatibility and benchmark impact

No change for e2b 2.46–2.61 except the clearer error in (1). With e2b 2.62, a sandbox that stops mid-command now yields a SandboxExecResult with error_type="sandbox" instead of a TimeoutError.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally.
  • Documentation added or updated, or N/A with justification. (N/A: no documented behavior changes.)
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header. (N/A: no new files.)
  • All commits have DCO sign-off.

On Python 3.11+ concurrent.futures.TimeoutError is the builtin
TimeoutError, so a TimeoutError raised by the sandbox operation itself
was caught by the sync-loop wait handler and reported as
"timed out waiting for the sync loop after 3600s". Only report a wait
timeout when the future is still pending; otherwise return its outcome.
run() now shares the wait handling with call().

Signed-off-by: Maksim Obukhov <[email protected]>
E2B 2.62 raises SandboxNotRunningException, a TimeoutException subclass,
when the sandbox was killed, paused or reached its lifetime. exec()
wrapped it as a command TimeoutError. Return the non-process sentinel
with error_type="sandbox" instead, as the Docker, Apptainer and
OpenShell providers do for a sandbox that is gone. Older E2B versions
without the class keep the TimeoutError path.

Signed-off-by: Maksim Obukhov <[email protected]>
E2B 2.62 builds its envd clients with get_transport(config, for_streaming=...,
retry_connect=False) and lets callers pin http_version. Gym's replacement
factory rejected both keywords, so with Gym's aiohttp transport active every
AsyncSandbox construction raised TypeError and E2BProvider.create failed after
E2B had already started the sandbox, which then ran until its timeout.

Accept and ignore both: GymAiohttpTransport never retries connections, and
aiohttp only speaks HTTP/1.1. The real-SDK test now looks through the response
retry transport that E2B 2.62 wraps around the API client's transport.

Signed-off-by: Maksim Obukhov <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 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.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Nov 3, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 4, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond bug Something isn't working area:sandbox Sandbox providers, isolation, and sandbox runtime contracts labels Nov 5, 2026
@OndrejDrapalik

Copy link
Copy Markdown

hey @hemildesai, could you take a look when you get a sec? the transport fix overlaps your draft #4597, happy to drop it from here. thanks!

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Nov 13, 2026

@hemildesai hemildesai 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.

Thanks for these fixes, and for the clear write-up with before/after runs against hosted E2B. That made this easy to review.

All three changes look correct to me:

  • Sync wrapper: checking future.done() before relabelling a TimeoutError is the right fix for Python 3.11+, where concurrent.futures.TimeoutError is the builtin. Routing run() through _wait_for_result also means call() and run() now share one implementation.
  • SandboxNotRunningException: returning error_type="sandbox" with return code 125 matches the Docker, Apptainer and OpenShell providers. The getattr lookup keeps older e2b versions working, and checking it before the generic TimeoutException is the right order.
  • Transport keywords: accepting http_version / retry_connect and ignoring them is correct for GymAiohttpTransport. The real-SDK test now also unwraps the 2.62 retry transport, which is a nice touch.

On the overlap with #4597 (raised in the comment above): the transport change there is identical, and your version is more complete (it also covers the API client's wrapped transport in the real-SDK test). Please keep it here. #4597 can be closed in favour of this PR, so there's no need to drop anything.

Locally, tests/unit_tests/test_sandbox.py and tests/unit_tests/test_e2b_provider.py pass on this head (191 passed, 21 skipped). CI hasn't run yet; I'll approve once a maintainer has triggered it and it's green.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 16, 2026
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 16, 2026
@hemildesai

Copy link
Copy Markdown
Contributor

/ok to test 1d4d55c

hemildesai
hemildesai previously approved these changes Nov 16, 2026

@hemildesai hemildesai 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.

CI is green on 1d4d55c. The only failures are the non-blocking harness conformance (kilocode) probes, which this PR doesn't touch. Approving. Thanks again for the fixes and the clear write-up!

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 16, 2026
Merge captured base 06146a1 into PR NVIDIA-NeMo#5509. Keep the automatic merge without manual changes.

Signed-off-by: svcnemo-autobot <[email protected]>
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

/ok to test 0838556

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 16, 2026 22:28

@hemildesai hemildesai 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.

Re-approving after the merge from main (0838556), which dismissed my earlier approval. The PR's own changes are the same as the version I reviewed (only the tests moved to tests/unit_tests/sandbox/ along with main), and CI is green on this head.

@yfw
yfw added this pull request to the merge queue Nov 17, 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/43989479912

@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/43991645372

Merged via the queue into NVIDIA-NeMo:main with commit 810abfd Nov 17, 2026
79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sandbox Sandbox providers, isolation, and sandbox runtime contracts bug Something isn't working community-request Issue reported or requested by someone from the community ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants