Skip to content

fix(sandbox): keep reused E2B workbench leases within the runtime cap - #8758

Merged
waleedlatif1 merged 4 commits into
stagingfrom
fix/e2b-session-lease-cap
Oct 7, 2026
Merged

waleedlatif1 merged 4 commits into
stagingfrom
fix/e2b-session-lease-cap

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • E2B kills a running sandbox 24h after it last started or resumed and silently clamps any longer timeout (persistence docs: pause + resume resets the count). findSessionSandbox recorded requestedAt + max(5min, endAt - now, lease) as the session deadline, so a workbench reconnected late in its life claimed a lease past the cap, outlives() skipped the extension, and E2B killed the workbench mid-run
  • Every E2B handle now carries the cap (startedAt + 24h, or the connect time when resuming a paused workbench), and the session deadline is clamped to it in one place, covering both the reconnect and extendLifetime
  • When a running workbench cannot fit the requested lease before its cap, it is paused (Sandbox.pause) and resumed through the existing Sandbox.connect, which restarts E2B's runtime count with files, packages and processes intact instead of replacing the workbench
  • A pause failure is logged and the workbench is reused with an honest, capped deadline. A resume failure propagates like any other reconnect failure; the workbench stays paused and the next acquire resumes it, rather than creating a second workbench under the same session key
  • Reaching the cap on a reconnected workbench is now classified as provider_limit instead of a user-code timeout (exit 124), since providerLimitAtMs was previously only set on a fresh create with exactly a 24h lifetime. A timeout counts as the cap only when the command's own deadline, measured from E2B dispatch, would have outlived it, so a short command timing out near the cap stays a user timeout
  • Workbench file reads and upload snapshots pass their idle lease into the reconnect instead of extending afterwards, so they get the same reset

Type of Change

  • Bug fix

Testing

  • New E2B continuous-runtime cap cases in e2b-session.test.ts run against a fake control plane that clamps timeouts to the cap and restarts it on resume: capped deadline when pausing fails (including after extendLifetime), pause + resume when the lease cannot fit, and provider_limit at the cap. All three fail on the previous code; reverting each guard individually turns its test red
  • Caller tests in session-files.test.ts / session-file-snapshot.test.ts that fail when the reconnect is not asked for the idle lease
  • lib/execution/remote-sandbox/ + lib/mothership suites, bun run lint, bun run type-check, bun run check:audits, docs-manifest:check, block-registry check
  • Root bun run test

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

E2B kills a running sandbox 24h after it last started or resumed and
silently clamps any longer timeout. Reconnecting to a workbench late in
its life recorded a lease past that cap, so outlives() skipped the
extension and a run cut off at the cap was reported as a user timeout.

- Track the cap on every handle and never record a session deadline past it
- Pause and resume a running workbench whose lease cannot fit before its cap,
  which resets E2B's runtime count with files and processes intact
- Classify a timeout at the cap of a reconnected workbench as provider_limit
@vercel

vercel Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 7, 2026 8:24pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Changes how sandbox session leases interact with the runtime cap.

The PR appears safe to merge; no new actionable issues were found.

What we checked:

  • Reads keep their idle lease: findSessionSandbox includes the requested lease in the E2B reconnect timeout. The caller no longer needs a separate extension.

Summary

Keeps reused E2B workbench leases within the continuous-runtime cap. Workbenches near the cap can pause and resume to grant a new lease.

  • File reads and upload snapshots now request their idle lease during reconnect.
  • Recorded deadlines stay capped when pause fails.
  • Both earlier timeout-classification findings are fixed in the current code. Their supplied threads were unnumbered.
  • No new actionable issues were found.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Reconnect to workbench with requested lease] --> B{Lease fits before runtime cap?}
  B -->|Yes| E[Connect and grant lease]
  B -->|No| C[Pause workbench]
  C -->|Success| D[Resume with fresh runtime cap]
  C -->|Failure| E
  D --> E
  E --> F[Record deadline no later than cap]
Loading

Reviews (4) · Last reviewed commit: "fix(sandbox): let workbench file reads r..." · Reviewed by Greptile

Comment thread apps/sim/lib/execution/remote-sandbox/e2b.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 2 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/execution/remote-sandbox/e2b.ts">

<violation number="1" location="apps/sim/lib/execution/remote-sandbox/e2b.ts:503">
P2: `commandDeadlineAtMs` is captured before process recording and E2B dispatch, although `timeoutMs` starts when `commands.run` starts. Near the 24-hour cap, setup delay can make an E2B provider timeout return as `timedOut` instead of `provider_limit`; capture the timestamp immediately before dispatch.</violation>
</file>

Comment thread apps/sim/lib/execution/remote-sandbox/e2b.ts Outdated
Comment thread apps/sim/lib/execution/remote-sandbox/e2b.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/remote-sandbox/e2b.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit bd7085e into staging Oct 7, 2026
36 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/e2b-session-lease-cap branch October 7, 2026 21:45

This branch was previously deployed

1 inactive deployment
Preview — 75382855 Deployed Oct 7, 2026 by vercel[bot]
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