Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Chnage id to template_id; Add migrations; Update docs

Tomas Valenta6fc7d32c7377
diff --git a/apps/docs/src/app/guide/custom-sandbox/page.mdx b/apps/docs/src/app/guide/custom-sandbox/page.mdx
index 3234c33af..a998de2bc 100644
--- a/apps/docs/src/app/guide/custom-sandbox/page.mdx
+++ b/apps/docs/src/app/guide/custom-sandbox/page.mdx
@@ -129,9 +129,9 @@ This will create the `e2b.toml` file storing the sandbox config.
<CodeGroup isFileName title="e2b.toml" isRunnable={false}>
```toml
# This is a config for E2B sandbox template
-template = "1wdqsf9le9gk21ztb4mo"
+template_id = "1wdqsf9le9gk21ztb4mo"
dockerfile = "e2b.Dockerfile"
-name = "my-agent-sandbox"
+template_name = "my-agent-sandbox"
```
</CodeGroup>
diff --git a/apps/docs/src/app/sandbox/templates/start-cmd/page.mdx b/apps/docs/src/app/sandbox/templates/start-cmd/page.mdx
index 0e125fb2f..bddd9e7bc 100644
--- a/apps/docs/src/app/sandbox/templates/start-cmd/page.mdx
+++ b/apps/docs/src/app/sandbox/templates/start-cmd/page.mdx
@@ -61,9 +61,9 @@ You can find the start command for the sandbox template in the `e2b.toml`:
<CodeGroup isFileName title="e2b.toml" isRunnable={false}>
```toml
# This is a config for E2B sandbox template
-id = "1wdqsf9le9gk21ztb4mo"
+template_id = "1wdqsf9le9gk21ztb4mo"
dockerfile = "e2b.Dockerfile"
-name = "my-agent-sandbox"
+template_name = "my-agent-sandbox"
start_cmd = "npm start" # $HighlightLine
```
</CodeGroup>
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts
index 9dc65ec6c..80756ae06 100644
--- a/packages/cli/src/commands/build.ts
+++ b/packages/cli/src/commands/build.ts
@@ -104,18 +104,18 @@ export const buildCommand = new commander.Command('build')
console.log(
`Found sandbox template ${asFormattedSandboxTemplate(
{
- envID: config.template,
- aliases: config.name ? [config.name] : undefined,
+ envID: config.template_id,
+ aliases: config.template_name ? [config.template_name] : undefined,
},
relativeConfigPath,
)}`,
)
- envID = config.template
+ envID = config.template_id
dockerfile = opts.dockerfile || config.dockerfile
startCmd = opts.cmd || config.start_cmd
}
- if (config && template && config.template !== template) {
+ if (config && template && config.template_id !== template) {
// error: you can't specify different ID than the one in config
console.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)
@@ -126,12 +126,12 @@ export const buildCommand = new commander.Command('build')
respectDockerignore: true,
})
- if (newName && config?.name && newName !== config?.name) {
+ if (newName && config?.template_name && newName !== config?.template_name) {
console.log(
- `The sandbox template name will be changed from ${asLocal(config.name)} to ${asLocal(newName)}.`,
+ `The sandbox template name will be changed from ${asLocal(config.template_name)} to ${asLocal(newName)}.`,
)
}
- const name = newName || config?.name
+ const name = newName || config?.template_name
console.log(
`Preparing sandbox template building (${filePaths.length} files in Docker build context). ${!filePaths.length ? `If you are using ${asLocal('.dockerignore')} check if it is configured correctly.` : ''}`,
@@ -189,9 +189,9 @@ export const buildCommand = new commander.Command('build')
await saveConfig(
configPath,
{
- template: build.envID,
+ template_id: build.envID,
dockerfile: dockerfileRelativePath,
- name,
+ template_name: name,
start_cmd: startCmd,
},
true,
diff --git a/packages/cli/src/commands/delete.ts b/packages/cli/src/commands/delete.ts
index c18ba763a..b7f1c2cbb 100644
--- a/packages/cli/src/commands/delete.ts
+++ b/packages/cli/src/commands/delete.ts
@@ -43,16 +43,16 @@ export const deleteCommand = new commander.Command('delete')
const root = getRoot(opts.path)
- const envs: (Pick<E2BConfig, 'template'> & { configPath?: string })[] = []
+ const envs: (Pick<E2BConfig, 'template_id'> & { configPath?: string })[] = []
if (template) {
envs.push({
- template,
+ template_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 => ({ template: e.envID, ...e })))
+ envs.push(...selectedEnvs.map(e => ({ template_id: e.envID, ...e })))
if (!envs || envs.length === 0) {
console.log('No sandbox templates selected')
@@ -81,7 +81,7 @@ export const deleteCommand = new commander.Command('delete')
}
console.log(chalk.default.red(chalk.default.underline('\nSandbox templates to delete')))
- envs.forEach(e => console.log(asFormattedSandboxTemplate({ ...e, envID: e.template }, e.configPath)))
+ envs.forEach(e => console.log(asFormattedSandboxTemplate({ ...e, envID: e.template_id }, 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.template }, e.configPath)}`)
- await deleteEnv(accessToken, { envID: e.template })
+ console.log(`- Deleting sandbox template ${asFormattedSandboxTemplate({ ...e, envID: e.template_id }, e.configPath)}`)
+ await deleteEnv(accessToken, { envID: e.template_id })
if (e.configPath) {
await deleteConfig(e.configPath)
}
diff --git a/packages/cli/src/commands/shell.ts b/packages/cli/src/commands/shell.ts
index 255d7ebc7..c28e41bbf 100644
--- a/packages/cli/src/commands/shell.ts
+++ b/packages/cli/src/commands/shell.ts
@@ -35,13 +35,13 @@ export const shellCommand = new commander.Command('shell')
console.log(
`Found sandbox template ${asFormattedSandboxTemplate(
{
- envID: config.template,
- aliases: config.name ? [config.name] : undefined,
+ envID: config.template_id,
+ aliases: config.template_name ? [config.template_name] : undefined,
},
relativeConfigPath,
)}`,
)
- envID = config.template
+ envID = config.template_id
}
if (!envID) {
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 10f12b2a6..3e16c349b 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -8,15 +8,26 @@ import { asFormattedSandboxTemplate, asLocalRelative } from 'src/utils/format'
export const configName = 'e2b.toml'
-const configCommentHeader = `# This is a config for E2B sandbox template
+function getConfigHeader(config: E2BConfig) {
+ return `# This is a config for E2B sandbox template.
+# You can use 'template_id' (${config.template_id}) ${config.template_name ? `or 'template_name (${config.template_name}) ` : ''}from this config to spawn a sandbox:
+
+# Python SDK
+# from e2b import Sandbox
+# sandbox = Sandbox(template='${config.template_name || config.template_id}')
+
+# JS SDK
+# import { Sandbox } from 'e2b'
+# const sandbox = await Sandbox.create({ template: '${config.template_name || config.template_id}' })
`
+}
export const configSchema = yup.object({
- name: yup.string(),
- template: yup.string().required(),
+ template_id: yup.string().required(),
+ template_name: yup.string().optional(),
dockerfile: yup.string().required(),
- start_cmd: yup.string(),
+ start_cmd: yup.string().optional(),
})
export type E2BConfig = yup.InferType<typeof configSchema>;
@@ -26,11 +37,16 @@ interface Migration {
to: string;
}
-// List of name migrations from old config format to new one
+// List of name migrations from old config format to new one.
+// We need to keep this list to be able to migrate old configs to new format.
const migrations: Migration[] = [
{
from: 'id',
- to: 'template',
+ to: 'template_id',
+ },
+ {
+ from: 'name',
+ to: 'template_name',
},
]
@@ -44,12 +60,13 @@ function applyMigrations(config: toml.JsonMap, migrations: Migration[]) {
delete config[from]
}
}
+
+ return config
}
export async function loadConfig(configPath: string) {
const tomlRaw = await fsPromise.readFile(configPath, 'utf-8')
const config = toml.parse(tomlRaw)
-
const migratedConfig = applyMigrations(config, migrations)
return (await configSchema.validate(migratedConfig)) as E2BConfig
@@ -75,12 +92,12 @@ export async function saveConfig(
})
const tomlRaw = toml.stringify(validatedConfig)
- await fsPromise.writeFile(configPath, configCommentHeader + tomlRaw)
+ await fsPromise.writeFile(configPath, getConfigHeader(config) + tomlRaw)
} catch (err: any) {
throw new Error(
`E2B sandbox template config ${asFormattedSandboxTemplate(
{
- envID: config.template,
+ envID: config.template_id,
},
configPath,
)} cannot be saved: ${err.message}`,