Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix(cli): print only the sandbox ID in detached sandbox create (#1762)
devin-ai-integration[bot]3202fadf9f43
diff --git a/.changeset/detached-sandbox-create-prints-id.md b/.changeset/detached-sandbox-create-prints-id.mdnew file mode 100644index 000000000..78b96943a--- /dev/null+++ b/.changeset/detached-sandbox-create-prints-id.md@@ -0,0 +1,5 @@+---+'@e2b/cli': patch+---++`e2b sandbox create --detach` now prints only the sandbox ID to stdout; the dashboard inspect link and other informational output go to stderr so the ID is easily parseable (e.g. `SBX=$(e2b sandbox create -d)`).diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.tsindex dc195491a..a106a3ff0 100644--- a/packages/cli/src/commands/sandbox/create.ts+++ b/packages/cli/src/commands/sandbox/create.ts@@ -87,9 +87,9 @@ export function createCommand(...(opts.timeout !== undefined ? { timeoutMs: opts.timeout } : {}),}const sandbox = await e2b.Sandbox.create(templateID, sandboxOpts)- printDashboardSandboxInspectUrl(sandbox.sandboxId)if (!opts.detach) {+ printDashboardSandboxInspectUrl(sandbox.sandboxId)await connectSandbox({sandbox,template: { templateID },@@ -104,9 +104,7 @@ export function createCommand(},})} else {- console.log(- `Sandbox created with ID ${sandbox.sandboxId} using template ${templateID}`- )+ console.log(sandbox.sandboxId)}process.exit(0)} catch (err: any) {diff --git a/packages/cli/tests/commands/sandbox/create_lifecycle.test.ts b/packages/cli/tests/commands/sandbox/create_lifecycle.test.tsindex 4650cb49c..e19ee32fe 100644--- a/packages/cli/tests/commands/sandbox/create_lifecycle.test.ts+++ b/packages/cli/tests/commands/sandbox/create_lifecycle.test.ts@@ -4,11 +4,13 @@ const mocks = vi.hoisted(() => {const create = vi.fn()const ensureAPIKey = vi.fn(() => 'test-api-key')const spawnConnectedTerminal = vi.fn()+ const printDashboardSandboxInspectUrl = vi.fn()return {create,ensureAPIKey,spawnConnectedTerminal,+ printDashboardSandboxInspectUrl,}})@@ -23,7 +25,7 @@ vi.mock('../../../src/api', () => ({}))vi.mock('src/utils/urls', () => ({- printDashboardSandboxInspectUrl: vi.fn(),+ printDashboardSandboxInspectUrl: mocks.printDashboardSandboxInspectUrl,}))vi.mock('src/terminal', () => ({@@ -296,6 +298,25 @@ describe('sandbox create lifecycle options', () => {expect(exitSpy).toHaveBeenCalledWith(1)})+ test('prints only the sandbox ID to stdout when detached', async () => {+ const exitSpy = vi+ .spyOn(process, 'exit')+ .mockImplementation((() => undefined) as never)+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})++ const { createCommand } = await import(+ '../../../src/commands/sandbox/create'+ )+ await createCommand('create', 'cr', false).parseAsync(+ ['base', '--detach'],+ { from: 'user' }+ )++ expect(logSpy.mock.calls).toEqual([['sandbox-id']])+ expect(mocks.printDashboardSandboxInspectUrl).not.toHaveBeenCalled()+ expect(exitSpy).toHaveBeenCalledWith(0)+ })+test('passes lifecycle and timeout together to Sandbox.create', async () => {const exitSpy = vi.spyOn(process, 'exit')