Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
feat(cli)!: stop reading e2b.toml outside template migrate (#1761)
devin-ai-integration[bot]3b599b85429c
diff --git a/.changeset/cli-drop-e2b-toml.md b/.changeset/cli-drop-e2b-toml.mdnew file mode 100644index 000000000..4644e824c--- /dev/null+++ b/.changeset/cli-drop-e2b-toml.md@@ -0,0 +1,5 @@+---+'@e2b/cli': minor+---++Stop reading `e2b.toml` in `sandbox create`, `template delete` and `template publish`/`unpublish`, and remove their `--config` and `--path` options. Templates must now be passed as an argument or picked interactively with `-s`. `template migrate` is unchanged and remains the only command that reads `e2b.toml`.diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.tsindex 89af35f3f..dc195491a 100644--- a/packages/cli/src/commands/sandbox/create.ts+++ b/packages/cli/src/commands/sandbox/create.ts@@ -1,14 +1,10 @@import * as e2b from 'e2b'import * as commander from 'commander'-import * as path from 'path'import { ensureAPIKey } from 'src/api'import { spawnConnectedTerminal, TerminalOpts } from 'src/terminal'import { asBold, asFormattedSandboxTemplate } from 'src/utils/format'-import { getRoot } from '../../utils/filesystem'-import { getConfigPath, loadConfig } from '../../config'-import fs from 'fs'-import { configOption, pathOption } from '../../options'+import { deprecatedConfigOption, warnIgnoredConfigOption } from '../../options'import { parseEnv } from '../../utils/env'import { printDashboardSandboxInspectUrl } from 'src/utils/urls'@@ -18,6 +14,7 @@ type SandboxLifecycle = {}const MIN_TIMEOUT_MS = 30_000+const DEFAULT_TEMPLATE = 'base'export function createCommand(name: string,@@ -28,10 +25,10 @@ export function createCommand(.description('create sandbox and connect terminal to it').argument('[template]',- `create and connect to sandbox specified by ${asBold('[template]')}`+ `create and connect to sandbox specified by ${asBold(+ '[template]'+ )}. Defaults to ${asBold(DEFAULT_TEMPLATE)}`)- .addOption(pathOption)- .addOption(configOption).option('-d, --detach', 'create sandbox without connecting terminal to it').option('--lifecycle.ontimeout <action>',@@ -51,14 +48,13 @@ export function createCommand(parseEnv,{} as Record<string, string>)+ .addOption(deprecatedConfigOption).alias(alias).action(async (template: string | undefined,opts: {name?: string- path?: string- config?: stringdetach?: boolean'lifecycle.ontimeout'?: SandboxLifecycle['onTimeout']'lifecycle.autoresume'?: boolean@@ -66,6 +62,7 @@ export function createCommand(user?: stringcwd?: stringenv?: Record<string, string>+ config?: string}) => {if (deprecated) {@@ -74,35 +71,11 @@ export function createCommand()}try {- const apiKey = ensureAPIKey()- let templateID = template+ warnIgnoredConfigOption(opts)- const root = getRoot(opts.path)- const configPath = getConfigPath(root, opts.config)-- const config = fs.existsSync(configPath)- ? await loadConfig(configPath)- : undefined- const relativeConfigPath = path.relative(root, configPath)-- if (!templateID && config) {- console.log(- `Found sandbox template ${asFormattedSandboxTemplate(- {- templateID: config.template_id,- aliases: config.template_name- ? [config.template_name]- : undefined,- },- relativeConfigPath- )}`- )- templateID = config.template_id- }+ const apiKey = ensureAPIKey()- if (!templateID) {- templateID = 'base'- }+ const templateID = template ?? DEFAULT_TEMPLATEconst lifecycle = buildLifecycle(opts['lifecycle.ontimeout'],diff --git a/packages/cli/src/commands/template/delete.ts b/packages/cli/src/commands/template/delete.tsindex d4bb000c9..6e1b642ba 100644--- a/packages/cli/src/commands/template/delete.ts+++ b/packages/cli/src/commands/template/delete.ts@@ -1,30 +1,20 @@import * as commander from 'commander'import * as chalk from 'chalk'-import * as fs from 'fs'import {asBold,asFormattedError,asFormattedSandboxTemplate,- asLocal,- asLocalRelative,+ SandboxTemplateRef,} from 'src/utils/format'import {- configOption,- pathOption,selectMultipleOption,+ deprecatedConfigOption,deprecatedTeamOption,projectIdFromOptions,projectOption,+ warnIgnoredConfigOption,} from 'src/options'-import {- E2BConfig,- configName,- deleteConfig,- getConfigPath,- loadConfig,-} from 'src/config'-import { getRoot } from 'src/utils/filesystem'import { listSandboxTemplates } from './list'import { getPromptTemplates } from 'src/utils/templatePrompt'import { confirm } from 'src/utils/confirm'@@ -45,46 +35,40 @@ async function deleteTemplate(templateID: string) {}export const deleteCommand = new commander.Command('delete')- .description(`delete sandbox template and ${asLocal(configName)} config`)+ .description('delete sandbox template').argument('[template]',- `specify ${asBold('[template]')} to delete it. If you dont specify ${asBold(+ `specify ${asBold('[template]'- )} the command will try to delete sandbox template defined by ${asLocal(- 'e2b.toml'- )}.`+ )} to delete it, or select templates interactively with ${asBold('-s')}`)- .addOption(pathOption)- .addOption(configOption).addOption(selectMultipleOption).addOption(projectOption).addOption(deprecatedTeamOption)+ .addOption(deprecatedConfigOption).alias('dl').option('-y, --yes', 'skip manual delete confirmation').action(async (template,opts: {- path?: string- config?: stringyes?: booleanselect?: booleanproject?: stringteam?: string+ config?: string}) => {try {- let projectId = projectIdFromOptions(opts)+ warnIgnoredConfigOption(opts)- const root = getRoot(opts.path)+ let projectId = projectIdFromOptions(opts)- const templates: (Pick<E2BConfig, 'template_id'> & {- configPath?: string- })[] = []+ const templates: SandboxTemplateRef[] = []if (template) {templates.push({- template_id: template,+ templateID: template,})} else if (opts.select) {projectId = resolveProjectId(projectId)@@ -99,8 +83,8 @@ export const deleteCommand = new commander.Command('delete'))templates.push(...selectedTemplates.map((e) => ({- template_id: e.templateID,- ...e,+ templateID: e.templateID,+ aliases: e.aliases,})))@@ -108,27 +92,6 @@ export const deleteCommand = new commander.Command('delete')console.log('No sandbox templates selected')return}- } else {- const configPath = getConfigPath(root, opts.config)- const config = fs.existsSync(configPath)- ? await loadConfig(configPath)- : undefined-- if (!config) {- console.log(- `No ${asLocal(configName)} found in ${asLocalRelative(- root- )}. Specify sandbox template with ${asBold(- '[template]'- )} argument or use interactive mode with ${asBold('-s')} flag.`- )- return- }-- templates.push({- ...config,- configPath,- })}if (!templates || templates.length === 0) {@@ -145,14 +108,7 @@ export const deleteCommand = new commander.Command('delete')chalk.default.underline('\nSandbox templates to delete')))- templates.forEach((e) =>- console.log(- asFormattedSandboxTemplate(- { ...e, templateID: e.template_id },- e.configPath- )- )- )+ templates.forEach((e) => console.log(asFormattedSandboxTemplate(e)))process.stdout.write('\n')if (!opts.yes) {@@ -171,15 +127,9 @@ export const deleteCommand = new commander.Command('delete')await Promise.all(templates.map(async (e) => {console.log(- `- Deleting sandbox template ${asFormattedSandboxTemplate(- { ...e, templateID: e.template_id },- e.configPath- )}`+ `- Deleting sandbox template ${asFormattedSandboxTemplate(e)}`)- await deleteTemplate(e.template_id)- if (e.configPath) {- await deleteConfig(e.configPath)- }+ await deleteTemplate(e.templateID)}))process.stdout.write('\n')diff --git a/packages/cli/src/commands/template/publish.ts b/packages/cli/src/commands/template/publish.tsindex e81bd8932..79a443af7 100644--- a/packages/cli/src/commands/template/publish.ts+++ b/packages/cli/src/commands/template/publish.ts@@ -1,24 +1,20 @@import * as commander from 'commander'import * as chalk from 'chalk'-import * as fs from 'fs'import {asBold,asFormattedError,asFormattedSandboxTemplate,- asLocal,- asLocalRelative,+ SandboxTemplateRef,} from 'src/utils/format'import {- configOption,+ deprecatedConfigOption,deprecatedTeamOption,- pathOption,projectIdFromOptions,projectOption,selectMultipleOption,+ warnIgnoredConfigOption,} from 'src/options'-import { configName, E2BConfig, getConfigPath, loadConfig } from 'src/config'-import { getRoot } from 'src/utils/filesystem'import { listSandboxTemplates } from './list'import { getPromptTemplates } from 'src/utils/templatePrompt'import { confirm } from 'src/utils/confirm'@@ -49,26 +45,23 @@ async function templateAction(publish: boolean,template: string,opts: {- path?: string- config?: stringyes?: booleanselect?: booleanproject?: stringteam?: string+ config?: string}) {try {- let projectId = projectIdFromOptions(opts)+ warnIgnoredConfigOption(opts)- const root = getRoot(opts.path)+ let projectId = projectIdFromOptions(opts)- const templates: (Pick<E2BConfig, 'template_id'> & {- configPath?: string- })[] = []+ const templates: SandboxTemplateRef[] = []if (template) {templates.push({- template_id: template,+ templateID: template,})} else if (opts.select) {projectId = resolveProjectId(projectId)@@ -96,8 +89,8 @@ async function templateAction()templates.push(...selectedTemplates.map((e) => ({- template_id: e.templateID,- ...e,+ templateID: e.templateID,+ aliases: e.aliases,})))@@ -105,27 +98,6 @@ async function templateAction(console.log('No sandbox templates selected')return}- } else {- const configPath = getConfigPath(root, opts.config)- const config = fs.existsSync(configPath)- ? await loadConfig(configPath)- : undefined-- if (!config) {- console.log(- `No ${asLocal(configName)} found in ${asLocalRelative(- root- )}. Specify sandbox template with ${asBold(- '[template]'- )} argument or use interactive mode with ${asBold('-s')} flag.`- )- return- }-- templates.push({- ...config,- configPath,- })}if (!templates || templates.length === 0) {@@ -142,14 +114,7 @@ async function templateAction(`Sandbox templates to ${publish ? 'publish' : 'unpublish'}`))- templates.forEach((e) =>- console.log(- asFormattedSandboxTemplate(- { ...e, templateID: e.template_id },- e.configPath- )- )- )+ templates.forEach((e) => console.log(asFormattedSandboxTemplate(e)))process.stdout.write('\n')if (!opts.yes) {@@ -176,12 +141,9 @@ async function templateAction(console.log(`- ${publish ? 'Publishing' : 'Unpublishing'- } sandbox template ${asFormattedSandboxTemplate(- { ...e, templateID: e.template_id },- e.configPath- )}`+ } sandbox template ${asFormattedSandboxTemplate(e)}`)- const names = await publishTemplate(e.template_id, publish)+ const names = await publishTemplate(e.templateID, publish)if (publish && names.length > 0) {console.log(` Published as: ${asBold(names.join(', '))}`)}@@ -200,17 +162,12 @@ export const publishCommand = new commander.Command('publish')'[template]',`specify ${asBold('[template]'- )} to publish it. If you dont specify ${asBold(- '[template]'- )} the command will try to publish sandbox template defined by ${asLocal(- 'e2b.toml'- )}.`+ )} to publish it, or select templates interactively with ${asBold('-s')}`)- .addOption(pathOption)- .addOption(configOption).addOption(selectMultipleOption).addOption(projectOption).addOption(deprecatedTeamOption)+ .addOption(deprecatedConfigOption).alias('pb').option('-y, --yes', 'skip manual publish confirmation').action(templateAction.bind(null, true))@@ -221,17 +178,12 @@ export const unPublishCommand = new commander.Command('unpublish')'[template]',`specify ${asBold('[template]'- )} to unpublish it. If you don't specify ${asBold(- '[template]'- )} the command will try to unpublish sandbox template defined by ${asLocal(- 'e2b.toml'- )}.`+ )} to unpublish it, or select templates interactively with ${asBold('-s')}`)- .addOption(pathOption)- .addOption(configOption).addOption(selectMultipleOption).addOption(projectOption).addOption(deprecatedTeamOption)+ .addOption(deprecatedConfigOption).alias('upb').option('-y, --yes', 'skip manual unpublish confirmation').action(templateAction.bind(null, false))diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 1533cd9fe..1c441ebfb 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -57,10 +57,6 @@ export async function loadConfig(configPath: string) {return (await configSchema.validate(migratedConfig)) as E2BConfig}-export async function deleteConfig(configPath: string) {- await fsPromise.unlink(configPath)-}-export function getConfigPath(root: string, configPath?: string) {if (configPath && path.isAbsolute(configPath)) return configPathdiff --git a/packages/cli/src/options.ts b/packages/cli/src/options.tsindex 2df55d41c..b29fcaab6 100644--- a/packages/cli/src/options.ts+++ b/packages/cli/src/options.ts@@ -25,6 +25,7 @@ export const pathOption = new commander.Option()} directory`)+// Only `template migrate` reads e2b.toml; no other command accepts this option.export const configOption = new commander.Option('--config <e2b-toml>',`specify path to the E2B config toml. By default E2B tries to find ${asBold(@@ -32,6 +33,29 @@ export const configOption = new commander.Option()} in root directory. We recommend using the new build system (https://e2b.dev/docs/template/defining-template) that does not use config files.`)+// Accepted but ignored by commands that used to read e2b.toml, so existing+// scripts keep working instead of failing with an opaque unknown option error.+export const deprecatedConfigOption = new commander.Option(+ '--config <e2b-toml>',+ `[deprecated] ${asBold('e2b.toml')} is no longer read here`+).hideHelp()++/**+ * Warn when the ignored --config flag is passed to a command that no longer+ * reads e2b.toml.+ */+export function warnIgnoredConfigOption(opts: { config?: string }) {+ if (!opts.config) return++ console.error(+ `The ${asBold('--config')} flag is no longer read here. Pass the template as ${asBold(+ '[template]'+ )} or select it with ${asBold('-s')}. ${asBold(+ 'e2b template migrate --config'+ )} still reads ${asLocal('e2b.toml')}.`+ )+}+export const selectMultipleOption = new commander.Option('-s, --select','select sandbox template from interactive list'diff --git a/packages/cli/src/utils/format.ts b/packages/cli/src/utils/format.tsindex 900f10a9d..c44537f22 100644--- a/packages/cli/src/utils/format.ts+++ b/packages/cli/src/utils/format.ts@@ -28,22 +28,20 @@ export function asFormattedTeam(return `${name} (${id})${isSelected}`}-export function asFormattedSandboxTemplate(- template: Pick<e2b.components['schemas']['Template'], 'templateID'> & {- aliases?: e2b.components['schemas']['Template']['aliases']- },- configLocalPath?: string-) {+export type SandboxTemplateRef = Pick<+ e2b.components['schemas']['Template'],+ 'templateID'+> & {+ aliases?: e2b.components['schemas']['Template']['aliases']+}++export function asFormattedSandboxTemplate(template: SandboxTemplateRef) {const aliases = listAliases(template.aliases)const name = aliases ? asBold(aliases) : ''- const configPath = configLocalPath- ? asDim(' <-> ') + asLocalRelative(configLocalPath)- : ''-const id = `${template.templateID} `- return `${id}${name}${configPath}`.trim()+ return `${id}${name}`.trim()}export function asRed(text: string) {diff --git a/packages/cli/tests/commands/template/delete.test.ts b/packages/cli/tests/commands/template/delete.test.tsdeleted file mode 100644index d7896cb96..000000000--- a/packages/cli/tests/commands/template/delete.test.ts+++ /dev/null@@ -1,71 +0,0 @@-import * as fs from 'fs/promises'-import * as os from 'os'-import * as path from 'path'-import { execSync } from 'child_process'-import { afterEach, beforeEach, describe, expect, test } from 'vitest'--describe('Template Delete --config', () => {- let testDir: string-- beforeEach(async () => {- testDir = await fs.mkdtemp(- path.join(os.tmpdir(), 'e2b-delete-config-test-')- )-- const defaultConfig = `template_id = "default-template-id"-dockerfile = "e2b.Dockerfile"`- await fs.writeFile(path.join(testDir, 'e2b.toml'), defaultConfig)-- const customConfig = `template_id = "custom-template-id"-dockerfile = "e2b.Dockerfile"`- await fs.writeFile(path.join(testDir, 'custom.toml'), customConfig)-- await fs.writeFile(path.join(testDir, 'e2b.Dockerfile'), 'FROM alpine:3.18')- })-- afterEach(async () => {- if (testDir) {- await fs.rm(testDir, { recursive: true, force: true })- }- })-- test('uses the config file passed via --config even when e2b.toml exists', async () => {- const cliPath = path.join(process.cwd(), 'dist', 'index.js')-- let output = ''- try {- output = execSync(- `node "${cliPath}" template delete --yes --path "${testDir}" --config custom.toml 2>&1`,- { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }- )- } catch (err: any) {- output = (err?.stdout ?? '') + (err?.stderr ?? '')- }-- expect(output).toContain('Sandbox templates to delete')- expect(output).toContain('custom-template-id')- expect(output).toContain('custom.toml')- expect(output).not.toContain('default-template-id')- })-- test('uses the default e2b.toml when --config is not provided', async () => {- const cliPath = path.join(process.cwd(), 'dist', 'index.js')-- let output = ''- try {- output = execSync(- `node "${cliPath}" template delete --yes --path "${testDir}" 2>&1`,- { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }- )- } catch (err: any) {- output = (err?.stdout ?? '') + (err?.stderr ?? '')- }-- expect(output).toContain('Sandbox templates to delete')- expect(output).toContain('default-template-id')- expect(output).toContain('e2b.toml')- expect(output).not.toContain('custom-template-id')- })-})--diff --git a/packages/cli/tests/commands/template/publish.test.ts b/packages/cli/tests/commands/template/publish.test.tsdeleted file mode 100644index ef7b7df96..000000000--- a/packages/cli/tests/commands/template/publish.test.ts+++ /dev/null@@ -1,77 +0,0 @@-import * as fs from 'fs/promises'-import * as os from 'os'-import * as path from 'path'-import { execSync } from 'child_process'-import { afterEach, beforeEach, describe, expect, test } from 'vitest'--describe('Template Publish --config', () => {- let testDir: string-- beforeEach(async () => {- testDir = await fs.mkdtemp(- path.join(os.tmpdir(), 'e2b-publish-config-test-')- )-- const defaultConfig = `template_id = "default-template-id"-dockerfile = "e2b.Dockerfile"`- await fs.writeFile(path.join(testDir, 'e2b.toml'), defaultConfig)-- const customConfig = `template_id = "custom-template-id"-dockerfile = "e2b.Dockerfile"`- await fs.writeFile(path.join(testDir, 'custom.toml'), customConfig)-- await fs.writeFile(path.join(testDir, 'e2b.Dockerfile'), 'FROM alpine:3.18')- })-- afterEach(async () => {- if (testDir) {- await fs.rm(testDir, { recursive: true, force: true })- }- })-- test('uses the config file passed via --config even when e2b.toml exists', async () => {- const cliPath = path.join(process.cwd(), 'dist', 'index.js')-- let output = ''- try {- // This will likely fail on the network call, but we only need stdout up to that point- output = execSync(- `node "${cliPath}" template publish --yes --path "${testDir}" --config custom.toml 2>&1`,- { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }- )- } catch (err: any) {- // Capture partial output from the failed process (expected due to no network)- output = (err?.stdout ?? '') + (err?.stderr ?? '')- }-- // It should log the sandbox template selection with the custom template ID and path- expect(output).toContain('Sandbox templates to publish')- expect(output).toContain('custom-template-id')- expect(output).toContain('custom.toml')- // And should not show the default template id when custom is provided- expect(output).not.toContain('default-template-id')- })-- test('uses the default e2b.toml when --config is not provided', async () => {- const cliPath = path.join(process.cwd(), 'dist', 'index.js')-- let output = ''- try {- output = execSync(- `node "${cliPath}" template publish --yes --path "${testDir}" 2>&1`,- { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }- )- } catch (err: any) {- output = (err?.stdout ?? '') + (err?.stderr ?? '')- }-- // Should reference the default config and template id- expect(output).toContain('Sandbox templates to publish')- expect(output).toContain('default-template-id')- expect(output).toContain('e2b.toml')- // Should not mention the custom config/template id- expect(output).not.toContain('custom-template-id')- })-})--