mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 18:01:30 +00:00
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>
35 lines
932 B
TypeScript
35 lines
932 B
TypeScript
import { SandboxAgent } from "sandbox-agent";
|
|
import { vercel } from "sandbox-agent/vercel";
|
|
|
|
function collectEnvVars(): Record<string, string> {
|
|
const env: Record<string, string> = {};
|
|
if (process.env.ANTHROPIC_API_KEY) env.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
|
|
if (process.env.OPENAI_API_KEY) env.OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
|
return env;
|
|
}
|
|
|
|
function inspectorUrlToBaseUrl(inspectorUrl: string): string {
|
|
return inspectorUrl.replace(/\/ui\/$/, "");
|
|
}
|
|
|
|
export async function setupVercelSandboxAgent(): Promise<{
|
|
baseUrl: string;
|
|
token?: string;
|
|
cleanup: () => Promise<void>;
|
|
}> {
|
|
const client = await SandboxAgent.start({
|
|
sandbox: vercel({
|
|
create: {
|
|
runtime: "node24",
|
|
env: collectEnvVars(),
|
|
},
|
|
}),
|
|
});
|
|
|
|
return {
|
|
baseUrl: inspectorUrlToBaseUrl(client.inspectorUrl),
|
|
cleanup: async () => {
|
|
await client.killSandbox();
|
|
},
|
|
};
|
|
}
|