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 diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.ts index 909bfb22f9..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,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