Repository navigation
fix(sandbox): correct E2B sandbox-stop errors and support e2b 2.62 - #5509
Conversation
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]>
|
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! |
hemildesai
left a comment
There was a problem hiding this comment.
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 aTimeoutErroris the right fix for Python 3.11+, whereconcurrent.futures.TimeoutErroris the builtin. Routingrun()through_wait_for_resultalso meanscall()andrun()now share one implementation. SandboxNotRunningException: returningerror_type="sandbox"with return code 125 matches the Docker, Apptainer and OpenShell providers. Thegetattrlookup keeps older e2b versions working, and checking it before the genericTimeoutExceptionis the right order.- Transport keywords: accepting
http_version/retry_connectand ignoring them is correct forGymAiohttpTransport. 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.
|
/ok to test 1d4d55c |
hemildesai
left a comment
There was a problem hiding this comment.
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!
Merge captured base 06146a1 into PR NVIDIA-NeMo#5509. Keep the automatic merge without manual changes. Signed-off-by: svcnemo-autobot <[email protected]>
|
/ok to test 0838556 |
hemildesai
left a comment
There was a problem hiding this comment.
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.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43989479912 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43991645372 |
What does this PR do?
Three small fixes in the sandbox layer, found while running a Gym environment on E2B with e2b 2.62:
future.result(timeout=3600). On Python 3.11+ thatTimeoutErroris the builtin one, so aTimeoutErrorraised 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.ttl_s) mid-command, e2b 2.62+ raisesSandboxNotRunningException.execnow returnserror_type="sandbox"(return code 125), as the Docker, Apptainer and OpenShell providers already do, instead of raisingTimeoutError. The class is looked up withgetattr, so e2b 2.46 still works.http_versionandretry_connectkeywords, 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;GymAiohttpTransportalready makes no connection retries and only speaks HTTP/1.1.CI pins e2b 2.46.0 in
uv.lock, bute2b>=2.46.0,<3.0.0allows 2.62, so any environment that resolves a newer e2b hit (2) and (3).Validation
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:
mainttl_s=15,sleep 60via the sync APIerror_type="sandbox", statusstoppedE2BCreateError ... unexpected keyword argument 'retry_connect', sandbox left runningexec,stop()workCompatibility 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
SandboxExecResultwitherror_type="sandbox"instead of aTimeoutError.Checklist
pre-commit run --all-files).