Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
start sandbox in detached mode using -d (#1147)
Mish Ushakova2cd86cfd42d
diff --git a/.changeset/fiery-icons-melt.md b/.changeset/fiery-icons-melt.mdnew file mode 100644index 000000000..3eaa409b0--- /dev/null+++ b/.changeset/fiery-icons-melt.md@@ -0,0 +1,5 @@+---+'@e2b/cli': patch+---++added -d option to create sandbox in detached modediff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.tsindex 7c29aadfa..909bfb22f 100644--- a/packages/cli/src/commands/sandbox/create.ts+++ b/packages/cli/src/commands/sandbox/create.ts@@ -24,6 +24,7 @@ export function createCommand().addOption(pathOption).addOption(configOption)+ .option('-d, --detach', 'create sandbox without connecting terminal to it').alias(alias).action(async (@@ -32,6 +33,7 @@ export function createCommand(name?: stringpath?: stringconfig?: string+ detach?: boolean}) => {if (deprecated) {@@ -70,7 +72,16 @@ export function createCommand(templateID = 'base'}- await connectSandbox({ apiKey, template: { templateID } })+ const sandbox = await e2b.Sandbox.create(templateID, { apiKey })+ printDashboardSandboxInspectUrl(sandbox.sandboxId)++ if (!opts.detach) {+ await connectSandbox({ sandbox, template: { templateID } })+ } else {+ console.log(+ `Sandbox created with ID ${sandbox.sandboxId} using template ${templateID}`+ )+ }process.exit(0)} catch (err: any) {console.error(err)@@ -81,16 +92,12 @@ export function createCommand(}export async function connectSandbox({- apiKey,+ sandbox,template,}: {- apiKey: string+ sandbox: e2b.Sandboxtemplate: Pick<e2b.components['schemas']['Template'], 'templateID'>}) {- const sandbox = await e2b.Sandbox.create(template.templateID, { apiKey })-- printDashboardSandboxInspectUrl(sandbox.sandboxId)-// keep-alive loopconst intervalId = setInterval(async () => {await sandbox.setTimeout(30_000)