Skip to content

feat(sandbox): add E2B network and custom extension create options - #5356

Merged
hemildesai merged 3 commits into
mainfrom
hemild/feat-e2b-network-extension-params
Oct 30, 2026
Merged

hemildesai merged 3 commits into
mainfrom
hemild/feat-e2b-network-extension-params

Conversation

@hemildesai

@hemildesai hemildesai commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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_access and secure, and E2BCreateConfig rejects unknown keys. This PR adds two optional create settings to cover that, for example "deny all egress except package registries" on AgentEnv:

  • create.network: allow_out / deny_out lists of CIDRs, IPs or hostnames, passed to AsyncSandbox.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's customExtensionParams (AgentEnv). The e2b SDK cannot send this field. When it is set, the provider creates the sandbox with POST {api_url}/sandboxes and then attaches with AsyncSandbox.connect(sandbox_id, timeout=<create timeout>). In detail:
    • The POST goes through the SDK's own API client (e2b.api.client_async.get_api_client). It therefore uses the same URL, auth headers (X-API-KEY plus connection.headers/api_headers), proxy, timeout and HTTP transport as AsyncSandbox.create, including the _sdk.py decision on when to use Gym's aiohttp pool.
    • Like the SDK create, the POST is never replayed: the transport retries only connections that were never made, and 429 rejections.
    • The body uses the API's NewSandbox fields, with network as allowOut / denyOut.
    • If connect fails or is cancelled after a successful POST, the provider kills the sandbox, because the caller has no handle to close it.
  • configs/e2b.yaml and the fern E2B guide document both settings with a default of null and a commented example. The README create row lists them.

Example:

create:
  network:
    deny_out: ["0.0.0.0/0"]
    allow_out: [pypi.org, files.pythonhosted.org, deb.debian.org, security.debian.org]
  custom_extension_params: {sandbank: all}

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 with e2b==2.46.0 installed. That test now binds network= on create, timeout= on connect and the class-level kill. It also checks that the SDK API client sends X-API-KEY and api_headers.
  • New unit tests (SDK and its API client mocked):
    • network reaches the SDK create only when it is set.
    • The REST path posts the exact body to /sandboxes, builds the API client from the connection config (with ready_timeout_s as the request timeout), attaches with connect using the create timeout, and does not call the SDK create.
    • A non-2xx response is wrapped in E2BCreateError and the POST is not retried.
    • A failed connect kills the created sandbox.
    • Invalid network and custom_extension_params values are rejected.
  • Compared offline with the real SDK's 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 without lifecycle, and allowPublicTraffic, whose API default is true.
  • ruff check and ruff format --check, and pre-commit run --files <changed files>: all pass.
  • Live smoke against an AgentEnv deployment using this provider path. A raw REST create with the same body has been checked by hand on AgentEnv; this PR stays a draft until the provider path is run for real.

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

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]>
@hemildesai hemildesai added feature New capabilities, enhancements, or enablement work area:sandbox Sandbox providers, isolation, and sandbox runtime contracts labels Oct 30, 2026
@copy-pr-bot

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

@hemildesai

Copy link
Copy Markdown
Contributor Author

/ok to test 2ffeda1

@hemildesai

Copy link
Copy Markdown
Contributor Author

/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]>
@hemildesai

Copy link
Copy Markdown
Contributor Author

/ok to test 6ae29af

@hemildesai

Copy link
Copy Markdown
Contributor Author

/review model=claude

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

  1. RISK, inline at provider.py L512. The REST create calls server_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 sync Sandbox facade closes that loop in stop(). The next create in the same process, for example an OSWorld revert_to_snapshot, then reuses a session whose loop is gone. _sdk.py deliberately keeps the SDK off Gym's pool in exactly these processes.
  2. RISK, inline at L527. If the POST succeeds and connect then 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.
  3. RISK, inline at L517. The REST headers come only from ConnectionConfig.headers. The shipped config and the fern guide document connection.api_headers as the place for gateway bearer auth. The real-SDK test does not check that .headers includes api_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.
  4. NOTE, docs (not anchorable in the diff). fern e2b.mdx is the user guide for this provider. Its shipped-config block still omits network and custom_extension_params. Its Security and Isolation section (L179-L182) covers only allow_internet_access. Egress allow/deny rules are a security-relevant, user-facing control (see the skill's Docs rule).
    • Fix:
      • Add both keys with null defaults to the YAML block, matching e2b.yaml L71-L81.
      • Add a short paragraph under Security and Isolation on create.network, including a deny_out: ["0.0.0.0/0"] plus allow_out example.
      • Add a sentence near the gateway section saying that custom_extension_params switches create to a single POST {api_url}/sandboxes followed by connect.
    • Acceptance (static): the fern YAML block lists the same create keys as e2b.yaml, and the README create row (README L76) stays consistent with it.

Checked and fine

  • Config validation and OmegaConf. resolve_provider_config calls _to_plain_dict, which runs OmegaConf.to_container(resolve=True) (config.py L64-L76). So ListConfig/DictConfig never reach the isinstance(rules, (list, tuple)) check or orjson.
  • Single send. _max_num_tries=1 and _resend_after_disconnect=False make _request_with_retries raise 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 aiohttp is justified. The managed venv installs -e nemo-gym[dev,ray] (requirements.txt L1), and server_utils already imports aiohttp at module level.
  • New tests. FakeSandbox.connect records its kwargs, so create_kwargs["timeout"] == 120 really 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.request and the shared-client lifecycle, _sdk.py, _http_transport.py, the sync Sandbox facade, 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]>
@hemildesai

Copy link
Copy Markdown
Contributor Author

/ok to test db4b4c1

@hemildesai

Copy link
Copy Markdown
Contributor Author

/review model=claude

@github-actions

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

  1. RISK, shared aiohttp session bound to a sandbox loop: fixed.
    • _create_with_extension_params no longer imports or calls server_utils. The POST now goes through e2b.api.client_async.get_api_client(config).get_async_httpx_client().
    • That client gets its transport from the factory that _sdk.py L52-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 as AsyncSandbox.create.
    • The real-SDK test asserts that api_client._transport is GymAiohttpTransport in the patched case (test L405-L414).
    • The POST is still sent once on the Gym transport. GymAiohttpTransport passes _max_connection_retries=1. With that setting, _request_with_retries raises after the first ServerDisconnectedError, ClientOSError or other error. It replays only explicit 429 rejections.
  2. RISK, sandbox leaked when connect fails after the POST: fixed.
    • provider.py L513-L525 catches BaseException around connect. That covers non-retryable errors, exhausted retries and cancellation. It then kills sandbox_id with AsyncSandbox.kill(sandbox_id, **self._api_params()), logs if the kill itself fails, and re-raises.
    • The outer except Exception still wraps ordinary errors as E2BCreateError, and CancelledError still propagates.
    • The success path never kills; test_extension_params_create_through_rest_api_then_connect asserts killed is False.
    • test_failed_connect_kills_the_created_sandbox would fail if the kill were removed.
    • The real-SDK test now binds AsyncSandbox._cls_kill("sbx-id", **ApiParams).
  3. RISK, connection.api_headers might not reach the REST create: fixed. The real-SDK test builds the API client from ConnectionConfig(api_headers={"Authorization": "Bearer t"}) and asserts that both X-API-KEY and Authorization are on its headers (test L406-L410). FakeConnectionConfig now only records kwargs, so it no longer assumes headers get merged.
  4. NOTE, docs: fixed.

Also checked and fine

  • The changed fakes match how the head code uses them: FakeApiClient.post(url, json), and FakeHttpResponse.status_code, .text and .json().
  • E2BCreateConfig validation has not changed since 6ae29af.
  • The OSWorld dependency-test exclusion was reverted, and that is consistent. provider.py no longer imports aiohttp, 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 since 6ae29af, and the paths they directly affect, for new regressions above that ceiling.
  • What I read: all five changed files, plus _sdk.py, _http_transport.py and server_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: how get_api_client builds its client, and that AsyncSandbox.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.

@hemildesai
hemildesai marked this pull request as ready for review October 30, 2026 19:04
@hemildesai
hemildesai 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/41112771403

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Oct 30, 2026

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

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

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

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

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

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026
@hemildesai
hemildesai 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/41138906269

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

Merged via the queue into main with commit c090185 Oct 30, 2026
57 of 60 checks passed
@hemildesai
hemildesai deleted the hemild/feat-e2b-network-extension-params branch October 30, 2026 23:14

This branch was previously deployed

1 inactive deployment
public — db4b4c11 Deployed Oct 30, 2026 by copy-pr-bot[bot] via release / finalize / notify #8595
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 feature New capabilities, enhancements, or enablement work 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.

3 participants