Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

cli: replace sandbox.kill() with setTimeout(1s) in create command to prevent snapshot deletions (#1256)

devin-ai-integration[bot]fcb95c34e2f3
diff --git a/.changeset/sandbox-timeout-instead-of-kill.md b/.changeset/sandbox-timeout-instead-of-kill.md
new file mode 100644
index 000000000..871b93a97
--- /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
diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.ts
index 909bfb22f..3205f8220 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<e2b.components['schemas']['Template'], 'templateID'>
}) {
- // 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<void> = Promise.resolve()
+ const intervalId = setInterval(() => {
+ pendingKeepAlive = sandbox.setTimeout(30_000)
}, 5_000)
console.log(
@@ -112,7 +113,8 @@ export async function connectSandbox({
await spawnConnectedTerminal(sandbox)
} finally {
clearInterval(intervalId)
- await sandbox.kill()
+ await pendingKeepAlive.catch(() => {})
+ await sandbox.setTimeout(1_000)
console.log(
`Closing terminal connection to template ${asFormattedSandboxTemplate(
template