Skip to content

fix(sandbox): kill E2B sandboxes at timeout instead of pausing them - #4598

Closed
hemildesai wants to merge 1 commit into
mainfrom
hemild/e2b-kill-on-timeout
Closed

hemildesai wants to merge 1 commit into
mainfrom
hemild/e2b-kill-on-timeout

Conversation

@hemildesai

Copy link
Copy Markdown
Contributor

What changed and why

The E2B provider never set the SDK's lifecycle on AsyncSandbox.create. Newer E2B SDKs (seen with 2.53.1) then send no autoPause at all and leave the timeout action to the server. Some E2B-compatible servers default to pausing a sandbox when its timeout expires. A paused sandbox is not reaped, so a sandbox whose client crashed or abandoned it stays around indefinitely, holding snapshot storage, instead of being deleted at its TTL.

Older SDKs (2.36, 2.46) sent autoPause=false by default, so this is a behaviour change that comes from upgrading the SDK, not from Gym.

The provider now passes lifecycle={"on_timeout": "kill"} on create, which sends autoPause=false on every SDK in the declared range (e2b>=2.36.0,<3.0.0). Normal runs are unaffected, because Gym deletes its own sandboxes; this only changes what happens to sandboxes that reach their timeout.

Issue: none filed. This is a small fix found while load-testing E2B-compatible sandboxes.

Validation

  • New unit test test_sandboxes_are_killed_not_paused_at_timeout: asserts the create kwargs carry lifecycle={"on_timeout": "kill"}. It fails without the change and passes with it.
  • The real-SDK call-shape check now also binds lifecycle against AsyncSandbox.create. I also checked directly that lifecycle binds on e2b 2.36.0, 2.46.0 and 2.53.1.
  • test_e2b_provider.py and test_e2b_build.py: 136 passed with the locked e2b 2.46.0.
  • pre-commit run --all-files: passed.

Rollout evidence

Against a live E2B-compatible gateway, I created two sandboxes with a 60 s timeout through the provider with this change and left them alone. Both were gone at 95 s: GET returned 404, and neither appeared in the paused listing. Without the change, sandboxes created the same way were still listed as paused hours after their timeout.

Compatibility

No config or API change. Sandboxes that reach their timeout are now always killed rather than left to the server's default. The provider has no pause or resume support, so nothing in Gym depended on the paused state.

Related: #4597 (newer SDK transport keywords).

🤖 Generated with Claude Code

The E2B provider never set the SDK's lifecycle. Newer SDKs then leave
autoPause unset and let the server decide, and some E2B-compatible
servers default to pausing timed-out sandboxes, which keeps them around
until someone deletes them. Pass lifecycle={"on_timeout": "kill"} on
create (accepted by every SDK in the declared range, e2b>=2.36), which
sends autoPause=false.

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

copy-pr-bot Bot commented Oct 14, 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 added a commit that referenced this pull request Oct 14, 2026
E2B 2.42+ (including the locked 2.46) sends no lifecycle fields unless
the caller sets them, and AgentENV then pauses timed-out sandboxes
without auto-resume and never evicts them, so crashed or cancelled runs
leak paused VMs. Default create.auto_resume to false, which sends
kill-on-timeout explicitly; null keeps the SDK/server default and is
documented as unsafe on AgentENV. Folds in #4598.

Review follow-ups: update the timeout/close wording and config snippet
in the docs and provider README, describe the post-resume minimum
timeout as an operator setting counted from the resume, note the 410
during pause/resume and that connect() resets the timeout to 300 s, pin
the AgentENV link, and add a real-SDK test that status sends only the
control-plane GET.

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

Copy link
Copy Markdown
Contributor Author

Folded into #3757 (ba72878), which now defaults create.auto_resume to false and sends kill-on-timeout explicitly. One correction to this PR's description: E2B 2.46 does NOT send autoPause=false by default. Only 2.36–2.41 do; 2.42+ omit the lifecycle fields, which is what makes the explicit default necessary.

@hemildesai hemildesai closed this Oct 14, 2026
@hemildesai
hemildesai deleted the hemild/e2b-kill-on-timeout branch October 14, 2026 18:57
hemildesai added a commit that referenced this pull request Nov 2, 2026
E2B 2.42+ (including the locked 2.46) sends no lifecycle fields unless
the caller sets them, and AgentENV then pauses timed-out sandboxes
without auto-resume and never evicts them, so crashed or cancelled runs
leak paused VMs. Default create.auto_resume to false, which sends
kill-on-timeout explicitly; null keeps the SDK/server default and is
documented as unsafe on AgentENV. Folds in #4598.

Review follow-ups: update the timeout/close wording and config snippet
in the docs and provider README, describe the post-resume minimum
timeout as an operator setting counted from the resume, note the 410
during pause/resume and that connect() resets the timeout to 300 s, pin
the AgentENV link, and add a real-SDK test that status sends only the
control-plane GET.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
hemildesai added a commit that referenced this pull request Nov 2, 2026
E2B 2.42+ (including the locked 2.46) sends no lifecycle fields unless
the caller sets them, and AgentENV then pauses timed-out sandboxes
without auto-resume and never evicts them, so crashed or cancelled runs
leak paused VMs. Default create.auto_resume to false, which sends
kill-on-timeout explicitly; null keeps the SDK/server default and is
documented as unsafe on AgentENV. Folds in #4598.

Review follow-ups: update the timeout/close wording and config snippet
in the docs and provider README, describe the post-resume minimum
timeout as an operator setting counted from the resume, note the 410
during pause/resume and that connect() resets the timeout to 300 s, pin
the AgentENV link, and add a real-SDK test that status sends only the
control-plane GET.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
yaoyu-33 pushed a commit to yaoyu-33/Gym that referenced this pull request Nov 2, 2026
* feat(sandbox): enable AgentENV auto-pause and resume

Expose an optional coupled pause/resume lifecycle policy, enable it in the AgentENV profile, and query control-plane status without waking paused sandboxes. Cover SDK request serialization and document the server-side resume timeout floor.

Signed-off-by: Hemil Desai <[email protected]>

* docs(sandbox): shorten lifecycle configuration comments

Signed-off-by: Hemil Desai <[email protected]>

* fix(sandbox): keep AgentENV benchmark config out of scope

Signed-off-by: Hemil Desai <[email protected]>

* fix(sandbox): kill E2B sandboxes at timeout by default

E2B 2.42+ (including the locked 2.46) sends no lifecycle fields unless
the caller sets them, and AgentENV then pauses timed-out sandboxes
without auto-resume and never evicts them, so crashed or cancelled runs
leak paused VMs. Default create.auto_resume to false, which sends
kill-on-timeout explicitly; null keeps the SDK/server default and is
documented as unsafe on AgentENV. Folds in NVIDIA-NeMo#4598.

Review follow-ups: update the timeout/close wording and config snippet
in the docs and provider README, describe the post-resume minimum
timeout as an operator setting counted from the resume, note the 410
during pause/resume and that connect() resets the timeout to 300 s, pin
the AgentENV link, and add a real-SDK test that status sends only the
control-plane GET.

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

* fix(sandbox): send the E2B lifecycle on the REST create path

With create.custom_extension_params set, the provider creates through
POST /sandboxes, which sent no lifecycle. Sandboxes created that way
(for example sandbank opt-ins) therefore missed the kill-on-timeout
default and could stay paused on AgentENV. Send the same autoPause and
autoResume fields the SDK create sends, and test both paths against the
real SDK serialization.

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

* test(sandbox): isolate real-SDK E2B tests and cover a deleted sandbox

The real-SDK lifecycle and status tests relied on an earlier test to
install Gym's transport; run alone they would reach the real E2B API.
Each now installs the transport itself. Add a 404 case showing that a
sandbox killed at its timeout reads STOPPED through the real SDK.

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

---------

Signed-off-by: Hemil Desai <[email protected]>
Co-authored-by: Hemil Desai <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant