From d7930c85c978c7c0cb5a7e3107ff279568bd9063 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 3 Apr 2026 22:25:57 +0000 Subject: [PATCH 1/3] cli: replace sandbox.kill() with setTimeout(1s) in create command Replace explicit sandbox.kill() with sandbox.setTimeout(1_000) in the connectSandbox finally block. This lets the sandbox expire implicitly after 1 second instead of killing it directly, preventing accidental historic sandbox snapshot deletions. Co-Authored-By: ben@e2b.dev --- packages/cli/src/commands/sandbox/create.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.ts index 909bfb22f9..873fea4e3c 100644 --- a/packages/cli/src/commands/sandbox/create.ts +++ b/packages/cli/src/commands/sandbox/create.ts @@ -112,7 +112,7 @@ export async function connectSandbox({ await spawnConnectedTerminal(sandbox) } finally { clearInterval(intervalId) - await sandbox.kill() + await sandbox.setTimeout(1_000) console.log( `Closing terminal connection to template ${asFormattedSandboxTemplate( template From 4612b725fcbee664221a06ffce960659f5cae5e9 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 3 Apr 2026 22:34:36 +0000 Subject: [PATCH 2/3] fix: await in-flight keep-alive before setting shutdown timeout Track the pending keep-alive promise and await it (with catch) in the finally block before setting the 1s shutdown timeout. This prevents a race where an already-started keep-alive could complete after our setTimeout(1_000) and re-extend the sandbox to 30s. Co-Authored-By: ben@e2b.dev --- packages/cli/src/commands/sandbox/create.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.ts index 873fea4e3c..3205f8220a 100644 --- a/packages/cli/src/commands/sandbox/create.ts +++ b/packages/cli/src/commands/sandbox/create.ts @@ -98,9 +98,10 @@ export async function connectSandbox({ sandbox: e2b.Sandbox template: Pick }) { - // keep-alive loop - const intervalId = setInterval(async () => { - await sandbox.setTimeout(30_000) + // keep-alive loop — track the in-flight promise so we can await it on shutdown + let pendingKeepAlive: Promise = Promise.resolve() + const intervalId = setInterval(() => { + pendingKeepAlive = sandbox.setTimeout(30_000) }, 5_000) console.log( @@ -112,6 +113,7 @@ export async function connectSandbox({ await spawnConnectedTerminal(sandbox) } finally { clearInterval(intervalId) + await pendingKeepAlive.catch(() => {}) await sandbox.setTimeout(1_000) console.log( `Closing terminal connection to template ${asFormattedSandboxTemplate( From 0bf5632cd8f892de217003cef792f362d8ccbdfd Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 3 Apr 2026 23:08:00 +0000 Subject: [PATCH 3/3] add changeset for CLI sandbox timeout change Co-Authored-By: ben@e2b.dev --- .changeset/sandbox-timeout-instead-of-kill.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sandbox-timeout-instead-of-kill.md diff --git a/.changeset/sandbox-timeout-instead-of-kill.md b/.changeset/sandbox-timeout-instead-of-kill.md new file mode 100644 index 0000000000..871b93a976 --- /dev/null +++ b/.changeset/sandbox-timeout-instead-of-kill.md @@ -0,0 +1,5 @@ +--- +'@e2b/cli': patch +--- + +Replace sandbox.kill() with sandbox.setTimeout(1s) in the CLI create command to prevent accidental historic sandbox snapshot deletions