Skip to content

armgit / E2B

Public Imported from GitHub
0

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

fix(cli): use latest Template.build API with name parameter (#1209)

Mish Ushakov8abfa627cb56
diff --git a/.changeset/template-init-name-syntax.md b/.changeset/template-init-name-syntax.md
new file mode 100644
index 000000000..82c9ed1de
--- /dev/null
+++ b/.changeset/template-init-name-syntax.md
@@ -0,0 +1,5 @@
+---
+"@e2b/cli": patch
+---
+
+fix(cli): use `name` parameter instead of deprecated `alias` in template init generated code
diff --git a/packages/cli/src/commands/template/generators/handlebars.ts b/packages/cli/src/commands/template/generators/handlebars.ts
index 05ed90a2f..44a0d5918 100644
--- a/packages/cli/src/commands/template/generators/handlebars.ts
+++ b/packages/cli/src/commands/template/generators/handlebars.ts
@@ -108,7 +108,7 @@ export async function transformTemplateData(
*/
export async function generateTypeScriptCode(
template: TemplateClass,
- alias: string,
+ name: string,
cpuCount?: number,
memoryMB?: number
): Promise<{ templateContent: string; buildContent: string }> {
@@ -138,7 +138,7 @@ export async function generateTypeScriptCode(
const templateContent = generateTemplateSource(templateData)
const buildContent = generateBuildSource({
- alias,
+ name,
cpuCount,
memoryMB,
})
@@ -154,7 +154,7 @@ export async function generateTypeScriptCode(
*/
export async function generatePythonCode(
template: TemplateClass,
- alias: string,
+ name: string,
cpuCount?: number,
memoryMB?: number,
isAsync: boolean = false
@@ -184,7 +184,7 @@ export async function generatePythonCode(
})
const buildContent = generateBuildSource({
- alias,
+ name,
cpuCount,
memoryMB,
})
@@ -199,7 +199,7 @@ export async function generatePythonCode(
* Generate README.md content using Handlebars
*/
export async function generateReadmeContent(
- alias: string,
+ name: string,
templateDir: string,
generatedFiles: GeneratedFiles
): Promise<string> {
@@ -216,7 +216,7 @@ export async function generateReadmeContent(
// Prepare template data
const templateData = {
- alias,
+ name,
templateDir,
templateFile: generatedFiles.templateFile,
buildDevFile: generatedFiles.buildDevFile,
diff --git a/packages/cli/src/commands/template/generators/template-generator.ts b/packages/cli/src/commands/template/generators/template-generator.ts
index 72b1897d6..9967abf89 100644
--- a/packages/cli/src/commands/template/generators/template-generator.ts
+++ b/packages/cli/src/commands/template/generators/template-generator.ts
@@ -10,7 +10,7 @@ import { TemplateClass } from 'e2b'
*/
export async function generateAndWriteTemplateFiles(
root: string,
- alias: string,
+ name: string,
language: Language,
template: TemplateClass,
cpuCount?: number,
@@ -21,13 +21,13 @@ export async function generateAndWriteTemplateFiles(
const { templateContent, buildContent: buildDevContent } =
await generateTypeScriptCode(
template,
- `${alias}-dev`,
+ `${name}-dev`,
cpuCount,
memoryMB
)
const { buildContent: buildProdContent } = await generateTypeScriptCode(
template,
- alias,
+ name,
cpuCount,
memoryMB
)
@@ -57,14 +57,14 @@ export async function generateAndWriteTemplateFiles(
const { templateContent, buildContent: buildDevContent } =
await generatePythonCode(
template,
- `${alias}-dev`,
+ `${name}-dev`,
cpuCount,
memoryMB,
isAsync
)
const { buildContent: buildProdContent } = await generatePythonCode(
template,
- alias,
+ name,
cpuCount,
memoryMB,
isAsync
diff --git a/packages/cli/src/commands/template/init.ts b/packages/cli/src/commands/template/init.ts
index 9fd9ae607..3f2503131 100644
--- a/packages/cli/src/commands/template/init.ts
+++ b/packages/cli/src/commands/template/init.ts
@@ -22,7 +22,7 @@ const DEFAULT_TEMPLATE_NAME = 'my-template'
*/
async function generateTemplateFiles(
root: string,
- alias: string,
+ name: string,
language: Language,
cpuCount?: number,
memoryMB?: number
@@ -31,7 +31,7 @@ async function generateTemplateFiles(
return generateAndWriteTemplateFiles(
root,
- alias,
+ name,
language,
template,
cpuCount,
@@ -158,7 +158,7 @@ function validateTemplateName(name: string) {
export const initCommand = new commander.Command('init')
.description('initialize a new sandbox template using the SDK')
.addOption(pathOption)
- .option('-n, --name <name>', 'template name (alias)', (value) => {
+ .option('-n, --name <name>', 'template name', (value) => {
try {
validateTemplateName(value)
} catch (err) {
@@ -197,7 +197,7 @@ export const initCommand = new commander.Command('init')
let templateName: string = opts.name ?? DEFAULT_TEMPLATE_NAME
if (opts.name === undefined) {
templateName = await input({
- message: 'Enter template name (alias):',
+ message: 'Enter template name:',
default: DEFAULT_TEMPLATE_NAME,
validate: (input: string) => {
try {
diff --git a/packages/cli/src/commands/template/migrate.ts b/packages/cli/src/commands/template/migrate.ts
index 9375053e2..72d7ef774 100644
--- a/packages/cli/src/commands/template/migrate.ts
+++ b/packages/cli/src/commands/template/migrate.ts
@@ -66,15 +66,15 @@ async function migrateToLanguage(
parsedTemplate = baseTemplate.setReadyCmd(config.ready_cmd)
}
- const alias = config.template_name || config.template_id
- if (!alias) {
+ const name = config.template_name || config.template_id
+ if (!name) {
throw new Error('Template name or ID is required')
}
// Generate code for the target language using shared functionality
await generateAndWriteTemplateFiles(
root,
- alias,
+ name,
language,
parsedTemplate,
config.cpu_count,
diff --git a/packages/cli/src/templates/python-build-async.hbs b/packages/cli/src/templates/python-build-async.hbs
index ca29d434d..7dee8d823 100644
--- a/packages/cli/src/templates/python-build-async.hbs
+++ b/packages/cli/src/templates/python-build-async.hbs
@@ -6,7 +6,7 @@ from .template import template
async def main():
await AsyncTemplate.build(
template,
- "{{alias}}",
+ "{{name}}",
{{#if cpuCount}}
cpu_count={{cpuCount}},
{{/if}}
diff --git a/packages/cli/src/templates/python-build-sync.hbs b/packages/cli/src/templates/python-build-sync.hbs
index 59cd6e092..3282d48bc 100644
--- a/packages/cli/src/templates/python-build-sync.hbs
+++ b/packages/cli/src/templates/python-build-sync.hbs
@@ -5,7 +5,7 @@ from .template import template
if __name__ == "__main__":
Template.build(
template,
- "{{alias}}",
+ "{{name}}",
{{#if cpuCount}}
cpu_count={{cpuCount}},
{{/if}}
diff --git a/packages/cli/src/templates/readme.hbs b/packages/cli/src/templates/readme.hbs
index 9c95e0d3a..94bb3834f 100644
--- a/packages/cli/src/templates/readme.hbs
+++ b/packages/cli/src/templates/readme.hbs
@@ -1,4 +1,4 @@
-# {{alias}} - E2B Sandbox Template
+# {{name}} - E2B Sandbox Template
This is an E2B sandbox template that allows you to run code in a controlled environment.
@@ -53,7 +53,7 @@ Once your template is built, you can use it in your E2B sandbox:
import { Sandbox } from 'e2b'
// Create a new sandbox instance
-const sandbox = await Sandbox.create('{{alias}}')
+const sandbox = await Sandbox.create('{{name}}')
// Your sandbox is ready to use!
console.log('Sandbox created successfully')
@@ -63,7 +63,7 @@ console.log('Sandbox created successfully')
from e2b import Sandbox
# Create a new sandbox instance
-sandbox = Sandbox.create('{{alias}}')
+sandbox = Sandbox.create('{{name}}')
# Your sandbox is ready to use!
print('Sandbox created successfully')
@@ -75,7 +75,7 @@ import asyncio
async def main():
# Create a new sandbox instance
- sandbox = await AsyncSandbox.create('{{alias}}')
+ sandbox = await AsyncSandbox.create('{{name}}')
# Your sandbox is ready to use!
print('Sandbox created successfully')
diff --git a/packages/cli/src/templates/typescript-build.hbs b/packages/cli/src/templates/typescript-build.hbs
index f1f15b6c6..1566af2d4 100644
--- a/packages/cli/src/templates/typescript-build.hbs
+++ b/packages/cli/src/templates/typescript-build.hbs
@@ -2,7 +2,7 @@ import { Template, defaultBuildLogger } from 'e2b'
import { template } from './template'
async function main() {
- await Template.build(template, '{{alias}}', {
+ await Template.build(template, '{{name}}', {
{{#if cpuCount}}
cpuCount: {{cpuCount}},
{{/if}}