Skip to content

armgit / E2B

Public Imported from GitHub
0

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

start sandbox in detached mode using -d (#1147)

Mish Ushakova2cd86cfd42d
diff --git a/.changeset/fiery-icons-melt.md b/.changeset/fiery-icons-melt.md
new file mode 100644
index 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 mode
diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.ts
index 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?: string
path?: string
config?: 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.Sandbox
template: Pick<e2b.components['schemas']['Template'], 'templateID'>
}) {
- const sandbox = await e2b.Sandbox.create(template.templateID, { apiKey })
-
- printDashboardSandboxInspectUrl(sandbox.sandboxId)
-
// keep-alive loop
const intervalId = setInterval(async () => {
await sandbox.setTimeout(30_000)