Repository navigation
feat(sandbox): add automatic job attribution to the E2B provider - #5607
Conversation
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]>
|
/ok to test c130b6f |
|
/review model=claude |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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 samekwargs["metadata"]feeds both the SDKAsyncSandbox.createpath and the REST body in_create_with_extension_params. Removing the oldif spec.metadata:guard is safe: - Config wiring.
attributiongoes through the same_config_from_mappingas the other E2B config blocks, so unknown keys are rejected andAttributionConfig.__post_init__checks the prefix. The new keyword has a default, so existingE2BProvider(...)callers don't change. - Tests. The tests that assert exact metadata don't depend on the environment:
test_spec_fields_map_onto_sdk_kwargsturns attribution off, and the REST test pins all four fields. The log-once test patches_logged_attributionon the module that defines it. These tests would fail if the precedence were reversed, if the REST path dropped attribution, or ifenabled: falsewere ignored. The fake SDK recordscreate_kwargsand the POST body exactly as sent. - Docs and config. The resolution order, the
rootexclusion, theNEMO_GYM_CONFIG_PATHfallback, the per-processrunid and the log-once behavior ine2b.mdx, the README ande2b.yamlall matchattribution.py. The#job-attributionandopensandbox#attribution-in-kubernetes-deploymentsanchors 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.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41871700654 |
…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]>
Summary
The E2B provider forwarded
SandboxSpec.metadatato 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 ine2b.default_metadata. OpenSandbox and OpenShell already add this automatically.E2BProvidertakes anattributionconfig, using the sharedAttributionConfig. It is on by default, as it is for OpenSandbox and OpenShell.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 SDKAsyncSandbox.createand the RESTPOST /sandboxespath used withcustom_extension_params. The resolved values are logged once per process.e2b.yaml, the provider README ande2b.mdxeach get anattributionblock and a "Job Attribution" section. It mirrorsopensandbox.mdxand shows how to filter withGET /v2/sandboxes?metadata=k=v(E2B and AgentENV) and how to clean up a run withAsyncSandbox.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
attribution.enabled: falseto send only explicit metadata.user(Slurm user or OS login) andteam(Slurm account) are stored as sandbox metadata in the E2B account.runis generated per process unlessNEMO_GYM_RUN_IDis set.Test plan
TestAttributiontests intests/unit_tests/test_e2b_provider.pyassert 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 emptykey_prefix, and invalid or unknown config rejected. ThePOST /sandboxestest now asserts the attribution keys in the request body.pyteston the E2B provider/endpoint/build/transport-fallback tests,test_sandbox_attribution.py, the OpenSandbox and OpenShell provider tests,agents/test_sandbox_session.pyand the OSWorld sandbox provider tests: 566 passed, 4 skipped (per-worktree venv, e2b 2.46.0).pre-commit run --all-filesAsyncSandbox.list(query=SandboxQuery(metadata=...))callsGET /v2/sandboxeswith the metadata urlencoded, and the paginator exposeshas_next/next_items()returningSandboxInfo.sandbox_id. Not run against a live service.🤖 Generated with Claude Code