Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Update template naming in CLI; Add migration for the e2b.toml field
Tomas Valenta876e1f801fb1
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.tsindex f149e07fd..bd4131819 100644--- a/packages/cli/src/commands/build.ts+++ b/packages/cli/src/commands/build.ts@@ -42,11 +42,11 @@ export const buildCommand = new commander.Command('build'))} config`,).argument(- '[id]',+ '[template]',`Specify ${asBold(- '[id]',- )} of sandbox template to rebuild it. If you don's specify ${asBold(- '[id]',+ '[template]',+ )} to rebuild it. If you don's specify ${asBold(+ '[template]',)} and there is no ${asLocal('e2b.toml')} a new sandbox will be created`,).addOption(pathOption)@@ -67,7 +67,7 @@ export const buildCommand = new commander.Command('build').alias('bd').action(async (- id: string | undefined,+ template: string | undefined,opts: {path?: string;dockerfile?: string;@@ -87,7 +87,7 @@ export const buildCommand = new commander.Command('build')process.exit(1)}- let envID = id+ let envID = templatelet dockerfile = opts.dockerfilelet startCmd = opts.cmd@@ -104,18 +104,18 @@ export const buildCommand = new commander.Command('build')console.log(`Found sandbox template ${asFormattedSandboxTemplate({- envID: config.id,+ envID: config.template,aliases: config.name ? [config.name] : undefined,},relativeConfigPath,)}`,)- envID = config.id+ envID = config.templatedockerfile = opts.dockerfile || config.dockerfilestartCmd = opts.cmd || config.start_cmd}- if (config && id && config.id !== id) {+ if (config && template && config.template !== template) {// error: you can't specify different ID than the one in configconsole.error("You can't specify different ID than the one in config. If you want to build a new sandbox template remove the config file.")process.exit(1)@@ -189,7 +189,7 @@ export const buildCommand = new commander.Command('build')await saveConfig(configPath,{- id: build.envID,+ template: build.envID,dockerfile: dockerfileRelativePath,name,start_cmd: startCmd,@@ -255,7 +255,7 @@ async function waitForBuildFinish(const pythonExample = asPython(`from e2b import Sandbox# Start sandbox-sandbox = Sandbox(id="${aliases?.length ? aliases[0] : template.data.envID}")+sandbox = Sandbox(template="${aliases?.length ? aliases[0] : template.data.envID}")# Interact with sandbox. Learn more here:# https://e2b.dev/docs/sandbox/overview@@ -266,7 +266,7 @@ sandbox.close()`)const typescriptExample = asTypescript(`import { Sandbox } from '@e2b/sdk'// Start sandbox-const sandbox = await Sandbox.create({ id: '${aliases?.length ? aliases[0] : template.data.envID}' })+const sandbox = await Sandbox.create({ template: '${aliases?.length ? aliases[0] : template.data.envID}' })// Interact with sandbox. Learn more here:// https://e2b.dev/docs/sandbox/overviewdiff --git a/packages/cli/src/commands/delete.ts b/packages/cli/src/commands/delete.tsindex 19432b848..c18ba763a 100644--- a/packages/cli/src/commands/delete.ts+++ b/packages/cli/src/commands/delete.ts@@ -26,33 +26,33 @@ const deleteEnv = e2b.withAccessToken(export const deleteCommand = new commander.Command('delete').description(`Delete sanbdox template and ${asLocal(configName)} config`).argument(- '[id]',+ '[template]',`Specify ${asBold(- '[id]',- )} of sandbox template to delete it. If you don's specify ${asBold(- '[id]',+ '[template]',+ )} to delete it. If you don's specify ${asBold(+ '[template]',)} the command will try delete sandbox template defined by ${asLocal('e2b.toml')}.`,).addOption(pathOption).addOption(selectMultipleOption).alias('dl').option('-y, --yes', 'Skip manual delete confirmation')- .action(async (id, opts: { path?: string, yes?: boolean, select?: boolean }) => {+ .action(async (template, opts: { path?: string, yes?: boolean, select?: boolean }) => {try {const accessToken = ensureAccessToken()const root = getRoot(opts.path)- const envs: (Pick<E2BConfig, 'id'> & { configPath?: string })[] = []+ const envs: (Pick<E2BConfig, 'template'> & { configPath?: string })[] = []- if (id) {+ if (template) {envs.push({- id,+ template,})} else if (opts.select) {const allEnvs = await listSandboxTemplates({ accessToken })const selectedEnvs = await getPromptEnvs(allEnvs, 'Select sandbox templates to delete')- envs.push(...selectedEnvs.map(e => ({ id: e.envID, ...e })))+ envs.push(...selectedEnvs.map(e => ({ template: e.envID, ...e })))if (!envs || envs.length === 0) {console.log('No sandbox templates selected')@@ -65,7 +65,7 @@ export const deleteCommand = new commander.Command('delete'): undefinedif (!config) {- console.log(`No ${asLocal(configName)} found in ${asLocalRelative(root)}. Specify sandbox template ${asBold('[id]')} or use interactive mode with ${asBold('-s')} flag.`)+ 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}@@ -76,12 +76,12 @@ export const deleteCommand = new commander.Command('delete')}if (!envs || envs.length === 0) {- console.log(`No sandbox templates selected. Specify sandbox template ${asBold('[id]')} or use interactive mode with ${asBold('-s')} flag.`)+ console.log(`No sandbox templates selected. Specify sandbox template with ${asBold('[template]')} argument or use interactive mode with ${asBold('-s')} flag.`)return}console.log(chalk.default.red(chalk.default.underline('\nSandbox templates to delete')))- envs.forEach(e => console.log(asFormattedSandboxTemplate({ ...e, envID: e.id }, e.configPath)))+ envs.forEach(e => console.log(asFormattedSandboxTemplate({ ...e, envID: e.template }, e.configPath)))process.stdout.write('\n')if (!opts.yes) {@@ -98,8 +98,8 @@ export const deleteCommand = new commander.Command('delete')await Promise.all(envs.map(async e => {- console.log(`- Deleting sandbox template ${asFormattedSandboxTemplate({ ...e, envID: e.id }, e.configPath)}`)- await deleteEnv(accessToken, { envID: e.id })+ console.log(`- Deleting sandbox template ${asFormattedSandboxTemplate({ ...e, envID: e.template }, e.configPath)}`)+ await deleteEnv(accessToken, { envID: e.template })if (e.configPath) {await deleteConfig(e.configPath)}diff --git a/packages/cli/src/commands/shell.ts b/packages/cli/src/commands/shell.tsindex 85fd62081..255d7ebc7 100644--- a/packages/cli/src/commands/shell.ts+++ b/packages/cli/src/commands/shell.ts@@ -12,16 +12,16 @@ import { pathOption } from '../options'export const shellCommand = new commander.Command('shell').description('Connect terminal to sandbox')- .argument('[id]', `Connect to sandbox specified by ${asBold('[id]')}`)+ .argument('[template]', `Connect to sandbox specified by ${asBold('[template]')}`).addOption(pathOption).alias('sh')- .action(async (id: string | undefined, opts: {+ .action(async (template: string | undefined, opts: {name?: string;path?: string;}) => {try {const apiKey = ensureAPIKey()- let envID = id+ let envID = templateconst root = getRoot(opts.path)const configPath = getConfigPath(root)@@ -35,13 +35,13 @@ export const shellCommand = new commander.Command('shell')console.log(`Found sandbox template ${asFormattedSandboxTemplate({- envID: config.id,+ envID: config.template,aliases: config.name ? [config.name] : undefined,},relativeConfigPath,)}`,)- envID = config.id+ envID = config.template}if (!envID) {@@ -50,9 +50,8 @@ export const shellCommand = new commander.Command('shell'))process.exit(1)}- const template: Pick<e2b.components['schemas']['Environment'], 'envID'> = { envID: envID }- await connectSandbox({ apiKey, template: template })+ await connectSandbox({ apiKey, template: { envID } })// We explicitly call exit because the sandbox is keeping the program alive.// We also don't want to call sandbox.close because that would disconnect other users from the edit session.process.exit(0)@@ -71,7 +70,7 @@ export async function connectSandbox({}) {const sandbox = await e2b.Sandbox.create({apiKey,- id: template.envID,+ template: template.envID,})if (sandbox.terminal) {diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex b6db2d5b2..10f12b2a6 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -14,17 +14,45 @@ const configCommentHeader = `# This is a config for E2B sandbox templateexport const configSchema = yup.object({name: yup.string(),- id: yup.string().required(),+ template: yup.string().required(),dockerfile: yup.string().required(),start_cmd: yup.string(),})export type E2BConfig = yup.InferType<typeof configSchema>;+interface Migration {+ from: string;+ to: string;+}++// List of name migrations from old config format to new one+const migrations: Migration[] = [+ {+ from: 'id',+ to: 'template',+ },+]++function applyMigrations(config: toml.JsonMap, migrations: Migration[]) {+ for (const migration of migrations) {+ const from = migration.from+ const to = migration.to++ if (config[from]) {+ config[to] = config[from]+ delete config[from]+ }+ }+}+export async function loadConfig(configPath: string) {const tomlRaw = await fsPromise.readFile(configPath, 'utf-8')const config = toml.parse(tomlRaw)- return (await configSchema.validate(config)) as E2BConfig++ const migratedConfig = applyMigrations(config, migrations)++ return (await configSchema.validate(migratedConfig)) as E2BConfig}export async function saveConfig(@@ -52,7 +80,7 @@ export async function saveConfig(throw new Error(`E2B sandbox template config ${asFormattedSandboxTemplate({- envID: config.id,+ envID: config.template,},configPath,)} cannot be saved: ${err.message}`,