mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 21:03:26 +00:00
feat: add E2B auto-pause support with pause/kill/reconnect provider lifecycle
Add `pause()`, `kill()`, and `reconnect()` methods to the SandboxProvider interface so providers can support graceful suspension and permanent deletion as distinct operations. The E2B provider now uses `betaCreate` with `autoPause: true` by default, `betaPause()` for suspension, and surfaces `SandboxDestroyedError` on reconnect to a deleted sandbox. SDK exposes `pauseSandbox()` and `killSandbox()` alongside the existing `destroySandbox()`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
32f3c6c3bc
commit
77c8f1e3f3
12 changed files with 416 additions and 13 deletions
32
examples/e2b/src/e2b.ts
Normal file
32
examples/e2b/src/e2b.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { SandboxAgent } from "sandbox-agent";
|
||||
import { e2b } from "sandbox-agent/e2b";
|
||||
|
||||
function collectEnvVars(): Record<string, string> {
|
||||
const envs: Record<string, string> = {};
|
||||
if (process.env.ANTHROPIC_API_KEY) envs.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
|
||||
if (process.env.OPENAI_API_KEY) envs.OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
||||
return envs;
|
||||
}
|
||||
|
||||
function inspectorUrlToBaseUrl(inspectorUrl: string): string {
|
||||
return inspectorUrl.replace(/\/ui\/$/, "");
|
||||
}
|
||||
|
||||
export async function setupE2BSandboxAgent(): Promise<{
|
||||
baseUrl: string;
|
||||
token?: string;
|
||||
cleanup: () => Promise<void>;
|
||||
}> {
|
||||
const client = await SandboxAgent.start({
|
||||
sandbox: e2b({
|
||||
create: { envs: collectEnvVars() },
|
||||
}),
|
||||
});
|
||||
|
||||
return {
|
||||
baseUrl: inspectorUrlToBaseUrl(client.inspectorUrl),
|
||||
cleanup: async () => {
|
||||
await client.killSandbox();
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue