Repository navigation
feat(sandbox): add E2B network and custom extension create options - #5356
Conversation
Eval configs could not ask E2B-compatible deployments for egress rules or deployment-specific create parameters: the provider sent only allow_internet_access and secure, and unknown create keys are rejected. Add two optional create settings: - create.network: allow_out/deny_out lists, passed to the SDK create as network=. Unknown keys and non-list values are rejected. - create.custom_extension_params: sent as the API's customExtensionParams (AgentEnv). The e2b SDK cannot send that field, so when it is set the provider creates through POST /sandboxes on Gym's shared aiohttp client, sent once like the SDK create, and attaches with AsyncSandbox.connect using the create timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]>
|
/ok to test 2ffeda1 |
|
/review model=claude |
The e2b provider now imports aiohttp for its REST create path. aiohttp is a core nemo-gym dependency, so the managed OSWorld venv always has it through the editable nemo-gym requirement; exclude it like httpx instead of pinning it again in requirements.txt. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]>
|
/ok to test 6ae29af |
|
/review model=claude |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE. The opt-in create.network and create.custom_extension_params settings are well scoped, and the SDK path is unchanged when neither is set. The new POST /sandboxes path has three RISKs and there is one docs NOTE. None of these is a BLOCKER.
Findings
- RISK, inline at
provider.pyL512. The REST create callsserver_utils.request. When no shared aiohttp client exists yet, as in Ray workers, this creates the process-wide client on the current sandbox event loop. The syncSandboxfacade closes that loop instop(). The next create in the same process, for example an OSWorldrevert_to_snapshot, then reuses a session whose loop is gone._sdk.pydeliberately keeps the SDK off Gym's pool in exactly these processes. - RISK, inline at L527. If the POST succeeds and
connectthen fails, or the task is cancelled, the sandbox ID is dropped. The billable sandbox keeps running until its TTL, which defaults to 3600s. This breaks the AGENTS.md rule to stop every started sandbox on every path. - RISK, inline at L517. The REST headers come only from
ConnectionConfig.headers. The shipped config and the fern guide documentconnection.api_headersas the place for gateway bearer auth. The real-SDK test does not check that.headersincludesapi_headers, and the fake merges them by assumption. If the real SDK keeps them separate, every REST create against such a gateway is sent without its auth header. Please confirm. - NOTE, docs (not anchorable in the diff). fern
e2b.mdxis the user guide for this provider. Its shipped-config block still omitsnetworkandcustom_extension_params. Its Security and Isolation section (L179-L182) covers onlyallow_internet_access. Egress allow/deny rules are a security-relevant, user-facing control (see the skill's Docs rule).- Fix:
- Add both keys with
nulldefaults to the YAML block, matchinge2b.yamlL71-L81. - Add a short paragraph under Security and Isolation on
create.network, including adeny_out: ["0.0.0.0/0"]plusallow_outexample. - Add a sentence near the gateway section saying that
custom_extension_paramsswitches create to a singlePOST {api_url}/sandboxesfollowed byconnect.
- Add both keys with
- Acceptance (static): the fern YAML block lists the same
createkeys ase2b.yaml, and the READMEcreaterow (README L76) stays consistent with it.
- Fix:
Checked and fine
- Config validation and OmegaConf.
resolve_provider_configcalls_to_plain_dict, which runsOmegaConf.to_container(resolve=True)(config.py L64-L76). SoListConfig/DictConfignever reach theisinstance(rules, (list, tuple))check or orjson. - Single send.
_max_num_tries=1and_resend_after_disconnect=Falsemake_request_with_retriesraise after one attempt on every exception path (server_utils.py L795-L853). - Error messages. The non-2xx message includes only the status and the first 500 characters of the response body, never the API key.
- OSWorld dependency test. Excluding
aiohttpis justified. The managed venv installs-e nemo-gym[dev,ray](requirements.txt L1), andserver_utilsalready imports aiohttp at module level. - New tests.
FakeSandbox.connectrecords its kwargs, socreate_kwargs["timeout"] == 120really proves that connect receives the create timeout.
The PR's own test plan leaves the live AgentEnv smoke unchecked. Running that provider path for real, with two sequential creates in one process and a gateway that authenticates via api_headers, would confirm findings 1 and 3.
Coverage and limitations
- I inspected all 5 changed files and traced
server_utils.requestand the shared-client lifecycle,_sdk.py,_http_transport.py, the syncSandboxfacade, the OSWorld sandbox/Ray paths,resolve_provider_config/create_provider, and the fern E2B guide. - I split the work across three delegated child reviewers: REST lifecycle, config and wire contract, and tests and dependencies. All three finished, but only the REST-lifecycle report reached me. I inspected the config/wire and tests/dependency topics myself; the findings above reflect that.
- The e2b SDK and aiohttp sources are not in the tree. Statements about their behaviour are marked as unconfirmed, and the proposed tests are proposals that I have not run.
Review generated by claude. This was a full review. Request a full review with /review reset=true.
Address review findings on the customExtensionParams create path: - Send POST /sandboxes through the SDK's own API client instead of Gym's process-wide aiohttp session. The REST create then follows the transport decision in _sdk.py, so it never creates or binds the shared session on a short-lived sandbox event loop. URL, auth headers (including api_headers), proxy and timeout come from the same ConnectionConfig as the SDK create. - Kill the sandbox when connect fails after a successful POST, since the caller gets no handle to close it. - Revert the OSWorld dependency test exclusion: the provider no longer imports aiohttp. - Document create.network and create.custom_extension_params in the fern E2B guide. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]>
|
/ok to test db4b4c1 |
|
/review model=claude |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP. LGTM: no concerns found. All four findings from the previous review (review 5709599151, at 6ae29af) are fixed at db4b4c1, and the changes since then add no regression that meets this follow-up's bar.
Fixes I checked against the source
- RISK, shared aiohttp session bound to a sandbox loop: fixed.
_create_with_extension_paramsno longer imports or callsserver_utils. The POST now goes throughe2b.api.client_async.get_api_client(config).get_async_httpx_client().- That client gets its transport from the factory that
_sdk.pyL52-L79 patches only when the process already has Gym's client or an injected config. Elsewhere the SDK keeps its own transport, the same choice asAsyncSandbox.create. - The real-SDK test asserts that
api_client._transportisGymAiohttpTransportin the patched case (test L405-L414). - The POST is still sent once on the Gym transport.
GymAiohttpTransportpasses_max_connection_retries=1. With that setting,_request_with_retriesraises after the firstServerDisconnectedError,ClientOSErroror other error. It replays only explicit 429 rejections.
- RISK, sandbox leaked when
connectfails after the POST: fixed.- provider.py L513-L525 catches
BaseExceptionaroundconnect. That covers non-retryable errors, exhausted retries and cancellation. It then killssandbox_idwithAsyncSandbox.kill(sandbox_id, **self._api_params()), logs if the kill itself fails, and re-raises. - The outer
except Exceptionstill wraps ordinary errors asE2BCreateError, andCancelledErrorstill propagates. - The success path never kills;
test_extension_params_create_through_rest_api_then_connectassertskilled is False. test_failed_connect_kills_the_created_sandboxwould fail if the kill were removed.- The real-SDK test now binds
AsyncSandbox._cls_kill("sbx-id", **ApiParams).
- provider.py L513-L525 catches
- RISK,
connection.api_headersmight not reach the REST create: fixed. The real-SDK test builds the API client fromConnectionConfig(api_headers={"Authorization": "Bearer t"})and asserts that bothX-API-KEYandAuthorizationare on its headers (test L406-L410).FakeConnectionConfignow only records kwargs, so it no longer assumes headers get merged. - NOTE, docs: fixed.
- The fern shipped-config block now has the same
createkeys andnulldefaults ase2b.yamlL63-L84. - The gateway section explains the switch to
POST /sandboxesplusconnect. - Security and Isolation documents
create.network, with adeny_out/allow_outexample. - The README
createrow is consistent with both.
- The fern shipped-config block now has the same
Also checked and fine
- The changed fakes match how the head code uses them:
FakeApiClient.post(url, json), andFakeHttpResponse.status_code,.textand.json(). E2BCreateConfigvalidation has not changed since6ae29af.- The OSWorld dependency-test exclusion was reverted, and that is consistent.
provider.pyno longer importsaiohttp, and no OSWorld file differs from base.
Scope and limitations
- Scope: this is a follow-up to
6ae29af(impact ceiling: moderate). I verified the four earlier findings and their regression tests. I then checked the changes made since6ae29af, and the paths they directly affect, for new regressions above that ceiling. - What I read: all five changed files, plus
_sdk.py,_http_transport.pyandserver_utils._request_with_retries. - How the work was split: three delegated children each took one topic: REST transport, post-POST lifecycle and auth headers, and docs/config/test fixtures. Only the docs/config/tests report reached me. The other two children completed, but their reports did not arrive, so I inspected the transport and lifecycle/auth topics myself. The conclusions above reflect that.
- Unverified SDK behaviour: the e2b SDK source is not in the tree. Two points rest on the real-SDK test (
importorskip("e2b")), which I could not run: howget_api_clientbuilds its client, and thatAsyncSandbox.kill(sandbox_id, ...)dispatches to_cls_kill. - Live smoke: the AgentEnv live smoke in the PR's test plan is still unchecked.
Review generated by claude. This was a follow-up review. Request a full review with /review reset=true.
Review generated by claude. This was a findings-only review. Request a full review with /review reset=true.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41112771403 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP. LGTM — no concerns found within this same-head follow-up.
The current head matches the baseline reviewed in review 5709731032, so there are no subsequent changes eligible for new-regression discovery. Source inspection supports the previously acknowledged fixes:
- Transport and gateway authentication: the REST create uses the SDK API client rather than directly initializing Gym’s shared session (provider). The regression test explicitly checks API-key and bearer headers and the Gym transport.
- Post-create cleanup: failed or cancelled attachment enters the kill-and-reraise branch (cleanup). The failure test asserts cleanup of
sbx-rest; the neighboring success test retains its no-kill assertion. - Documentation: the guide’s defaults match the shipped YAML. The gateway explanation, egress-rule example and README option list are present.
All three delegated topic reviews completed and were consolidated against the source. All five changed files were inspected within this follow-up scope; this was not a fresh whole-PR review.
Limitations: no tests, documentation builds or live gateway requests were executed. External SDK client construction and class-level kill dispatch were assessed through the supplied call-shape tests, not independently verified SDK source or execution.
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 findings-only review. Request a full review with /review reset=true.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41113624527 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41114551628 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41115873799 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41121489995 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41124462631 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41138906269 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41139138519 |
Summary
Eval configs cannot ask an E2B-compatible deployment for egress rules or deployment-specific create parameters today. The E2B provider sends only
allow_internet_accessandsecure, andE2BCreateConfigrejects unknown keys. This PR adds two optionalcreatesettings to cover that, for example "deny all egress except package registries" on AgentEnv:create.network:allow_out/deny_outlists of CIDRs, IPs or hostnames, passed toAsyncSandbox.create(network=...). The provider rejects unknown keys and non-list values; for example, a bare string is rejected because the SDK would split it into characters.create.custom_extension_params: sent as the API'scustomExtensionParams(AgentEnv). The e2b SDK cannot send this field. When it is set, the provider creates the sandbox withPOST {api_url}/sandboxesand then attaches withAsyncSandbox.connect(sandbox_id, timeout=<create timeout>). In detail:e2b.api.client_async.get_api_client). It therefore uses the same URL, auth headers (X-API-KEYplusconnection.headers/api_headers), proxy, timeout and HTTP transport asAsyncSandbox.create, including the_sdk.pydecision on when to use Gym's aiohttp pool.NewSandboxfields, withnetworkasallowOut/denyOut.connectfails or is cancelled after a successful POST, the provider kills the sandbox, because the caller has no handle to close it.configs/e2b.yamland the fern E2B guide document both settings with a default ofnulland a commented example. The READMEcreaterow lists them.Example:
Compatibility: both settings are opt-in and default to
null, so existing configs behave as before.Issue: none. This is a small opt-in provider option needed by an AgentEnv deployment, so no public issue was filed.
Test plan
pytest tests/unit_tests/test_e2b_provider.py tests/unit_tests/test_e2b_endpoint.py tests/unit_tests/test_e2b_build.py tests/unit_tests/test_e2b_sdk_transport_fallback.py responses_api_agents/osworld_agent/tests/test_runtime_dependencies.py: 174 passed. This includes the real-SDK call-shape test withe2b==2.46.0installed. That test now bindsnetwork=on create,timeout=on connect and the class-level kill. It also checks that the SDK API client sendsX-API-KEYandapi_headers.networkreaches the SDK create only when it is set./sandboxes, builds the API client from the connection config (withready_timeout_sas the request timeout), attaches with connect using the create timeout, and does not call the SDK create.E2BCreateErrorand the POST is not retried.networkandcustom_extension_paramsvalues are rejected.NewSandbox(...).to_dict(): the REST body has the same fields and network keys (allowOut/denyOut). It omits two fields the SDK model fills with defaults:autoPause, which the real SDK create also leaves unset withoutlifecycle, andallowPublicTraffic, whose API default is true.ruff checkandruff format --check, andpre-commit run --files <changed files>: all pass.Rollout evidence: not yet. This change touches the sandbox provider only, and no environment or agent behavior changes unless the new settings are set.
🤖 Generated with Claude Code