Skip to content

feat(sandbox): add automatic job attribution to the E2B provider - #5607

Merged
hemildesai merged 1 commit into
mainfrom
hemild/e2b-attribution
Nov 4, 2026
Merged

hemildesai merged 1 commit into
mainfrom
hemild/e2b-attribution

Conversation

@hemildesai

@hemildesai hemildesai commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The E2B provider forwarded SandboxSpec.metadata to E2B but added no job attribution. E2B and AgentENV sandboxes could not be traced to the team, user, workload or run that created them unless someone set the metadata by hand in e2b.default_metadata. OpenSandbox and OpenShell already add this automatically.

  • E2BProvider takes an attribution config, using the shared AttributionConfig. It is on by default, as it is for OpenSandbox and OpenShell.
  • At create, the provider merges the nemo-gym.nvidia.com/{team,user,workload,run} keys under the explicit spec metadata, so explicit keys win. Both create paths get the keys: the SDK AsyncSandbox.create and the REST POST /sandboxes path used with custom_extension_params. The resolved values are logged once per process.
  • Create is still never retried, and nothing new goes into env vars, files or headers.
  • Docs: e2b.yaml, the provider README and e2b.mdx each get an attribution block and a "Job Attribution" section. It mirrors opensandbox.mdx and shows how to filter with GET /v2/sandboxes?metadata=k=v (E2B and AgentENV) and how to clean up a run with AsyncSandbox.list(query=SandboxQuery(...)). The "Integration Attribution" text no longer says the provider adds no metadata to the sandbox.

Issue: none. This brings the E2B provider in line with the existing OpenSandbox and OpenShell attribution. It is independent of #3810 (E2B pause/resume), which touches the same provider file. This branch is based on main.

Compatibility

  • Every E2B create now sends up to four extra metadata keys. No config migration is needed. Set attribution.enabled: false to send only explicit metadata.
  • On hosted e2b.dev, the resolved user (Slurm user or OS login) and team (Slurm account) are stored as sandbox metadata in the E2B account.
  • As with OpenSandbox, run is generated per process unless NEMO_GYM_RUN_ID is set.

Test plan

  • New TestAttribution tests in tests/unit_tests/test_e2b_provider.py assert the metadata sent to the SDK at create: attribution on by default and logged once (no API key in the log), explicit spec metadata winning, attribution turned off, an empty key_prefix, and invalid or unknown config rejected. The POST /sandboxes test now asserts the attribution keys in the request body.
  • pytest on the E2B provider/endpoint/build/transport-fallback tests, test_sandbox_attribution.py, the OpenSandbox and OpenShell provider tests, agents/test_sandbox_session.py and the OSWorld sandbox provider tests: 566 passed, 4 skipped (per-worktree venv, e2b 2.46.0).
  • pre-commit run --all-files
  • Docs snippets checked statically against the locked e2b 2.46.0: AsyncSandbox.list(query=SandboxQuery(metadata=...)) calls GET /v2/sandboxes with the metadata urlencoded, and the paginator exposes has_next / next_items() returning SandboxInfo.sandbox_id. Not run against a live service.
  • Full unit suite: left to CI.
  • Rollout evidence: N/A. The change only adds metadata keys to the create request; the unit tests check the exact create kwargs and REST body. It was not run against a live E2B or AgentENV deployment.

🤖 Generated with Claude Code

The E2B provider forwarded SandboxSpec.metadata but added no attribution, so
E2B and AgentENV sandboxes could not be traced to the team, user, workload or
run that created them unless metadata was set by hand.

Add an `attribution` config (shared AttributionConfig, on by default as for
OpenSandbox and OpenShell) and merge its nemo-gym.nvidia.com/{team,user,
workload,run} keys under the explicit spec metadata at create, on both the SDK
and the REST (customExtensionParams) create paths. The resolved attribution is
logged once per process. Document it in e2b.yaml, the provider README and
e2b.mdx, including filtering with GET /v2/sandboxes?metadata=k=v.

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 Nov 4, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 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 c130b6f

@hemildesai

Copy link
Copy Markdown
Contributor Author

/review model=claude

@hemildesai
hemildesai enabled auto-merge November 4, 2026 16:40

@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. I found no blocking or risky issues. There's one NOTE, phrased as a question, about whether a live E2B or AgentENV deployment accepts the attribution values (inline on provider.py).

What I checked

  • Merge in E2BProvider.create. {**self._attribution.metadata(), **spec.metadata} gives explicit spec keys precedence, which matches the docs. The same kwargs["metadata"] feeds both the SDK AsyncSandbox.create path and the REST body in _create_with_extension_params. Removing the old if spec.metadata: guard is safe:
    • SandboxSpec.metadata defaults to a dict (base.py).
    • SandboxConfig.spec always builds a dict, with default_metadata merged in first (config.py).
    • OpenSandbox already spreads **spec.metadata the same way.
  • Config wiring. attribution goes through the same _config_from_mapping as the other E2B config blocks, so unknown keys are rejected and AttributionConfig.__post_init__ checks the prefix. The new keyword has a default, so existing E2BProvider(...) callers don't change.
  • Tests. The tests that assert exact metadata don't depend on the environment: test_spec_fields_map_onto_sdk_kwargs turns attribution off, and the REST test pins all four fields. The log-once test patches _logged_attribution on the module that defines it. These tests would fail if the precedence were reversed, if the REST path dropped attribution, or if enabled: false were ignored. The fake SDK records create_kwargs and the POST body exactly as sent.
  • Docs and config. The resolution order, the root exclusion, the NEMO_GYM_CONFIG_PATH fallback, the per-process run id and the log-once behavior in e2b.mdx, the README and e2b.yaml all match attribution.py. The #job-attribution and opensandbox#attribution-in-kubernetes-deployments anchors both resolve, and the rewritten Integration Attribution text is accurate.

Limits. I couldn't run tests or reach E2B or AgentENV. Nothing in the repo confirms the external SDK and API usage in the docs: AsyncSandbox.list(query=SandboxQuery(...)), paginator.has_next/next_items, and GET /v2/sandboxes?metadata=k=v. I'm not reporting those as defects. If you tried the snippets against e2b 2.46, mentioning that in the PR would help readers trust them.

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

@hemildesai
hemildesai added this pull request to the merge queue Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit b465860 Nov 4, 2026
63 of 68 checks passed
@hemildesai
hemildesai deleted the hemild/e2b-attribution branch November 4, 2026 17:12
hemildesai added a commit that referenced this pull request Nov 4, 2026
…ilience

Resolve the E2B config and docs page against #5607: keep
operations.new_sandbox_grace_s and the new attribution block.

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

This branch was previously deployed

1 inactive deployment
public — c130b6f0 Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #10041
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants