Skip to content

autoresume: lifecycle component in sdk#1146

Open
matthewlouisbrockman wants to merge 44 commits intomainfrom
lifecycle-in-sdk
Open

autoresume: lifecycle component in sdk#1146
matthewlouisbrockman wants to merge 44 commits intomainfrom
lifecycle-in-sdk

Conversation

@matthewlouisbrockman
Copy link
Contributor

@matthewlouisbrockman matthewlouisbrockman commented Feb 19, 2026

Implements the lifecycle prop on Sandbox.create, taking over and deprecating the beta_pause functionality.

Currently supports:

  • on_timeout: kill (default) | pause. Controls what should happen to the sandbox when it hits end of life. Pause allows for resuming
  • auto_resume: False (default) | True. Whether the sandbox should autoresume on traffic

Intended for additional functionality as we update the backend to support additional props. Blocked from deploying until the API and client-proxy are deployed but for pre-approval.

(Meant to be extended later as add more capabilities to the API)


Note

Medium Risk
Changes sandbox creation request payloads in both JS and Python SDKs to support new lifecycle/auto-resume behavior, which could affect sandbox timeout/termination semantics. Backwards compatibility is partially preserved via deprecated autoPause/betaPause shims, but behavior depends on backend support.

Overview
Adds a new lifecycle option to Sandbox.create/AsyncSandbox.create that controls what happens on timeout (kill vs pause) and whether paused sandboxes auto-resume on traffic, mapping this to the API’s autoPause and autoResume.policy fields.

Promotes pausing to a stable API (Sandbox.pause / SandboxApi.pause in JS; Sandbox.pause / AsyncSandbox.pause in Python) and deprecates betaPause (and JS autoPause) with compatibility wrappers; JS Sandbox.connect() instance method now takes SandboxConnectOpts.

Updates and expands test coverage for pausing/resuming via connect and for lifecycle payload behavior (including auto-resume wakeup), plus a minor Python connect-return fix and small test cleanup.

Written by Cursor Bugbot for commit 504de2c. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Feb 19, 2026

🦋 Changeset detected

Latest commit: 504de2c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@e2b/python-sdk Minor
e2b Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

Package Artifacts

Built from 92a36d1. Download artifacts from this workflow run.

JS SDK (e2b@2.13.1-lifecycle-in-sdk.0):

npm install ./e2b-2.13.1-lifecycle-in-sdk.0.tgz

CLI (@e2b/cli@2.7.4-lifecycle-in-sdk.0):

npm install ./e2b-cli-2.7.4-lifecycle-in-sdk.0.tgz

Python SDK (e2b==2.14.0+lifecycle-in-sdk):

pip install ./e2b-2.14.0+lifecycle.in.sdk-py3-none-any.whl

@matthewlouisbrockman
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@matthewlouisbrockman
Copy link
Contributor Author

matthewlouisbrockman commented Feb 19, 2026

adding the changeset should not have caused tests to fail, tests seem a bit flaky for some reason (not related to this PR i don't think)

@matthewlouisbrockman matthewlouisbrockman changed the title (draft) lifecycle in sdk lifecycle in sdk Feb 21, 2026
@matthewlouisbrockman
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1e0ba8559

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Member

@mishushakov mishushakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all looks good, just:

  • let's do the param validation on the server side
  • I think mocks are not necessary here
  • instead of mock tests let's do full end to end test where we create a Sandbox with an auto-pause/auto-resume policy, waits until the timeout and then .connect to it again (or a http request to the sandbox url?)

@matthewlouisbrockman
Copy link
Contributor Author

got the issues - the end to end tests now pass on staging / fail on prod (expected; client proxy not live on prod yet so should fail)

"""


def get_auto_resume_policy(lifecycle: Optional[SandboxLifecycle]) -> Optional[str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just do this inline, no need for another function

assert False, "Sandbox not found"


def test_lifecycle_auto_resume_policy_mapping():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this

Copy link
Member

@mishushakov mishushakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved but:

  • unnecessary function get_auto_resume_policy which we don't have in JS.
  • i am confused you'd call auto_resume policy "any" - it's too vague, most people won't be able to infer the meaning of the setting (I know it's only on backend, but still).

@matthewlouisbrockman
Copy link
Contributor Author

approved but:

  • unnecessary function get_auto_resume_policy which we don't have in JS.
  • i am confused you'd call auto_resume policy "any" - it's too vague, most people won't be able to infer the meaning of the setting (I know it's only on backend, but still).

secure: opts?.secure ?? true,
allow_internet_access: opts?.allowInternetAccess ?? true,
network: opts?.network,
...(autoPause !== undefined ? { autoPause } : {}),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional autoPause !== undefined is always true

Low Severity

The autoPause variable is computed as lifecycle.onTimeout === 'pause', which always produces a boolean — never undefined. The conditional autoPause !== undefined on the spread is therefore always true, making the ternary dead code. This was likely written by analogy with the autoResumePolicy check below (where undefined IS a real possibility), but it's misleading here since a reader might incorrectly assume there's a path where autoPause is intentionally excluded from the body.

Additional Locations (1)

Fix in Cursor Fix in Web

@matthewlouisbrockman
Copy link
Contributor Author

approved but:

  • unnecessary function get_auto_resume_policy which we don't have in JS.
  • i am confused you'd call auto_resume policy "any" - it's too vague, most people won't be able to infer the meaning of the setting (I know it's only on backend, but still).

unnecessary function get_auto_resume_policy which we don't have in JS. - getting rid of that guy, ghost code that removed it everywhere else but left in the function

auto_resume policy "any" - - originally referred to what sort of traffic to resume. lemme see how painful it is to change it now that most of the API changes are in.

@matthewlouisbrockman
Copy link
Contributor Author

plan's it goes to any|http|envd|off eventually so the any | off for now is awkawrd but forward extensible I think

autoResume?: {
policy: 'any' | 'off'
}
} = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant type intersection for already-defined schema field

Low Severity

The type intersection & { autoResume?: { policy: 'any' | 'off' } } on the body variable is redundant because components['schemas']['NewSandbox'] already includes autoResume?: components["schemas"]["SandboxAutoResumeConfig"] which resolves to exactly { policy: "any" | "off" }. This adds unnecessary type complexity and misleadingly implies the generated schema doesn't support autoResume, when it already does.

Fix in Cursor Fix in Web

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

return None

auto_resume = lifecycle.get("auto_resume")
return "any" if auto_resume else "off"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer-acknowledged function still present after agreed removal

Low Severity

The get_auto_resume_policy helper function was explicitly flagged for removal/inlining in the PR review, and the author acknowledged they would remove it, but it remains in the final diff along with its duplicated tests. The JS SDK inlines the equivalent logic directly in createSandbox, creating an unnecessary asymmetry between the two SDKs. The function is only a few lines and the logic is simple enough to inline at the two call sites in sandbox_async/sandbox_api.py and sandbox_sync/sandbox_api.py.

Additional Locations (2)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request Improvement Improvement for current functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants