diff --git a/.changeset/moody-zebras-doubt.md b/.changeset/moody-zebras-doubt.md new file mode 100644 index 000000000..0c33badd8 --- /dev/null +++ b/.changeset/moody-zebras-doubt.md @@ -0,0 +1,5 @@ +--- +"@e2b/cli": patch +--- + +Update template naming field when using CLI diff --git a/.changeset/nasty-poets-press.md b/.changeset/nasty-poets-press.md new file mode 100644 index 000000000..e860976b1 --- /dev/null +++ b/.changeset/nasty-poets-press.md @@ -0,0 +1,6 @@ +--- +"@e2b/python-sdk": patch +"@e2b/sdk": patch +--- + +Deprecate id Sandbox parameter and add template parameter diff --git a/apps/docs/src/app/cli/commands/page.mdx b/apps/docs/src/app/cli/commands/page.mdx index 9af825162..17cffdbc0 100644 --- a/apps/docs/src/app/cli/commands/page.mdx +++ b/apps/docs/src/app/cli/commands/page.mdx @@ -17,7 +17,7 @@ e2b build ``` -Running `e2b build` without specifying a template with the `[id]` argument will rebuild template defined by the `e2b.toml` config. +Running `e2b build` without specifying a template with the `[template]` argument will rebuild template defined by the `e2b.toml` config. If there is no `e2b.toml` config a new template will be created. @@ -25,7 +25,7 @@ If there is no `e2b.toml` config a new template will be created. #### **Arguments** - @@ -71,7 +71,7 @@ e2b template init ## `delete` -Delete the sandbox template specified by the `[id]` argument, `e2b.toml` config in the working directory, or by an interactive selection. +Delete the sandbox template specified by the `[template]` argument, `e2b.toml` config in the working directory, or by an interactive selection. By default, the root directory is the current working directory. This command also deletes the `e2b.toml` config. @@ -81,13 +81,13 @@ e2b delete ``` -Running `e2b delete` without specifying a template with the `[id]` argument will delete the template defined by the `e2b.toml` config. +Running `e2b delete` without specifying a template with the `[template]` argument will delete the template defined by the `e2b.toml` config. #### **Arguments** - @@ -150,13 +150,13 @@ e2b shell ``` -Running `e2b shell` without specifying a template with the `[id]` argument will spawn sandbox defined by the `e2b.toml` config. +Running `e2b shell` without specifying a template with the `[template]` argument will spawn sandbox defined by the `e2b.toml` config. #### **Arguments** - diff --git a/apps/docs/src/app/guide/custom-sandbox/page.mdx b/apps/docs/src/app/guide/custom-sandbox/page.mdx index fc3f4d820..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. ```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" ``` @@ -153,7 +153,7 @@ e2b build Now you can use the [E2B SDK](/getting-started/installation) to spawn & control your new custom sandbox. -The sandbox template name is `my-agent-sandbox`. We'll use it as an unique identifier and pass it to the SDK as the `id` parameter. +The sandbox template name is `my-agent-sandbox`. We'll use it as an unique identifier and pass it to the SDK as the `template` parameter. This way, we'll be able to spawn our custom sandbox and control it with the SDK. @@ -161,7 +161,7 @@ This way, we'll be able to spawn our custom sandbox and control it with the SDK. import { Sandbox } from '@e2b/sdk' // Spawn your custom sandbox -const sandbox = await Sandbox.create({ id: 'my-agent-sandbox' }) // $HighlightLine +const sandbox = await Sandbox.create({ template: 'my-agent-sandbox' }) // $HighlightLine // Interact with sandbox. Learn more here: // https://e2b.dev/docs/sandbox/overview @@ -174,7 +174,7 @@ await sandbox.close() from e2b import Sandbox # Spawn your custom sandbox -sandbox = Sandbox(id="my-agent-sandbox") # $HighlightLine +sandbox = Sandbox(template="my-agent-sandbox") # $HighlightLine # Interact with sandbox. Learn more here: # https://e2b.dev/docs/sandbox/overview diff --git a/apps/docs/src/app/sandbox/custom/page.mdx b/apps/docs/src/app/sandbox/custom/page.mdx index d9de2928e..7a79675cb 100644 --- a/apps/docs/src/app/sandbox/custom/page.mdx +++ b/apps/docs/src/app/sandbox/custom/page.mdx @@ -20,7 +20,7 @@ Once you build your custom sandbox template, you can spawn multiple isolated san // Create new sandbox const sandbox = await Sandbox.create({ - id: '', // You get sandbox ID from the CLI after you run `$ e2b build` + template: '', // You get sandbox template ID from the CLI after you run `$ e2b build` }) // Close sandbox once done @@ -32,7 +32,7 @@ Once you build your custom sandbox template, you can spawn multiple isolated san # Create new sandbox sandbox = Sandbox( - id="", # You get sandbox ID from the CLI after you run `$ e2b build` + template="", # You get sandbox template from the CLI after you run `$ e2b build` ) # Close sandbox once done diff --git a/apps/docs/src/app/sandbox/templates/overview/page.mdx b/apps/docs/src/app/sandbox/templates/overview/page.mdx index 2efb58307..5efa6955c 100644 --- a/apps/docs/src/app/sandbox/templates/overview/page.mdx +++ b/apps/docs/src/app/sandbox/templates/overview/page.mdx @@ -32,8 +32,8 @@ Follow our [guide](/guide/custom-sandbox) on how to create a custom sandbox. // Create new sandbox const sandbox = await Sandbox.create({ - // You get sandbox ID from the CLI after you run `$ e2b build` - id: '', // $HighlightLine + // You get sandbox template from the CLI after you run `$ e2b build` + template: '', // $HighlightLine }) // Close sandbox once done @@ -45,8 +45,8 @@ Follow our [guide](/guide/custom-sandbox) on how to create a custom sandbox. # Create new sandbox sandbox = Sandbox( - # You get sandbox ID from the CLI after you run `$ e2b build` - id="", # $HighlightLine + # You get sandbox template from the CLI after you run `$ e2b build` + template="", # $HighlightLine ) # Close sandbox once done diff --git a/apps/docs/src/app/sandbox/templates/premade/page.mdx b/apps/docs/src/app/sandbox/templates/premade/page.mdx index ffd4d87c3..251eb0f6e 100644 --- a/apps/docs/src/app/sandbox/templates/premade/page.mdx +++ b/apps/docs/src/app/sandbox/templates/premade/page.mdx @@ -21,7 +21,7 @@ To get your started quickly, we offer two premade sandboxes. Template File
- id + template base
@@ -49,7 +49,7 @@ The base sandbox has all the features of the [Sandbox API](/sandbox/api/envs) av
- id + template Python3-CodeInterpreter
@@ -201,4 +201,3 @@ sandbox.close() - Stream code errors - Upload file - Download file */} - 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 71fdb6269..a98ff55ff 100644 --- a/apps/docs/src/app/sandbox/templates/start-cmd/page.mdx +++ b/apps/docs/src/app/sandbox/templates/start-cmd/page.mdx @@ -84,9 +84,9 @@ The start command is specified inside the `e2b.toml` in the same directory where ```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 = "" # $HighlightLine ``` diff --git a/apps/docs/src/code/js/agents/clone_repo.js b/apps/docs/src/code/js/agents/clone_repo.js index e7c37fe26..0df219261 100644 --- a/apps/docs/src/code/js/agents/clone_repo.js +++ b/apps/docs/src/code/js/agents/clone_repo.js @@ -3,7 +3,7 @@ import { Sandbox } from '@e2b/sdk' // 1. Start the playground sandbox const sandbox = await Sandbox.create({ // You can pass your own sandbox template id - id: 'base', + template: 'base', apiKey: process.env.E2B_API_KEY, }) diff --git a/apps/docs/src/code/js/agents/code_exec.js b/apps/docs/src/code/js/agents/code_exec.js index 5a2ab5363..01ea81c3c 100644 --- a/apps/docs/src/code/js/agents/code_exec.js +++ b/apps/docs/src/code/js/agents/code_exec.js @@ -3,7 +3,7 @@ import { Sandbox } from '@e2b/sdk' // 1. Start the playground sandbox const sandbox = await Sandbox.create({ // You can pass your own sandbox template id - id: 'base', + template: 'base', }) // 2. Save the JavaScript code to a file inside the playground diff --git a/apps/docs/src/code/js/agents/install_deps_npm.js b/apps/docs/src/code/js/agents/install_deps_npm.js index e7750712f..1f11877ac 100644 --- a/apps/docs/src/code/js/agents/install_deps_npm.js +++ b/apps/docs/src/code/js/agents/install_deps_npm.js @@ -2,7 +2,7 @@ import { Sandbox } from '@e2b/sdk' // 1. Start the playground sandbox const sandbox = await Sandbox.create({ - id: 'base', // $HighlightLine + template: 'base', // $HighlightLine apiKey: process.env.E2B_API_KEY, }) diff --git a/apps/docs/src/code/js/agents/start_process.js b/apps/docs/src/code/js/agents/start_process.js index 1f80e7dfa..7cc89eef4 100644 --- a/apps/docs/src/code/js/agents/start_process.js +++ b/apps/docs/src/code/js/agents/start_process.js @@ -3,7 +3,7 @@ import { Sandbox } from '@e2b/sdk' // 1. Start the playground sandbox const sandbox = await Sandbox.create({ // You can pass your own sandbox template id - id: 'base', + template: 'base', apiKey: process.env.E2B_API_KEY, }) diff --git a/apps/docs/src/code/js/basics/download_file.js b/apps/docs/src/code/js/basics/download_file.js index 9f0dffa19..807f49708 100644 --- a/apps/docs/src/code/js/basics/download_file.js +++ b/apps/docs/src/code/js/basics/download_file.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' import fs from 'node:fs' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) const buffer = await sandbox.downloadFile('path/to/remote/file/inside/sandbox') // $HighlightLine // Save file to local filesystem diff --git a/apps/docs/src/code/js/basics/fs_ls.js b/apps/docs/src/code/js/basics/fs_ls.js index 25d0280ab..6f4bfc880 100644 --- a/apps/docs/src/code/js/basics/fs_ls.js +++ b/apps/docs/src/code/js/basics/fs_ls.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', }) const dirContent = await sandbox.filesystem.list('/') // $HighlightLine diff --git a/apps/docs/src/code/js/basics/fs_mkdir.js b/apps/docs/src/code/js/basics/fs_mkdir.js index 0b22e8028..2817d9606 100644 --- a/apps/docs/src/code/js/basics/fs_mkdir.js +++ b/apps/docs/src/code/js/basics/fs_mkdir.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({ id: 'base' }) +const sandbox = await Sandbox.create({ template: 'base' }) // Create a new directory '/dir' await sandbox.filesystem.makeDir('/dir') // $HighlightLine diff --git a/apps/docs/src/code/js/basics/fs_read.js b/apps/docs/src/code/js/basics/fs_read.js index ddb869910..ac04b4ff3 100644 --- a/apps/docs/src/code/js/basics/fs_read.js +++ b/apps/docs/src/code/js/basics/fs_read.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) const fileContent = await sandbox.filesystem.read('/etc/hosts') // $HighlightLine console.log(fileContent) diff --git a/apps/docs/src/code/js/basics/fs_read_bytes.js b/apps/docs/src/code/js/basics/fs_read_bytes.js index ab0091ef4..b0f301340 100644 --- a/apps/docs/src/code/js/basics/fs_read_bytes.js +++ b/apps/docs/src/code/js/basics/fs_read_bytes.js @@ -1,7 +1,7 @@ import fs from 'fs' import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // File bytes will read file's content as bytes // `fileBytes` as a Uint8Array diff --git a/apps/docs/src/code/js/basics/fs_watch.js b/apps/docs/src/code/js/basics/fs_watch.js index e89486129..c620e6bc0 100644 --- a/apps/docs/src/code/js/basics/fs_watch.js +++ b/apps/docs/src/code/js/basics/fs_watch.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // Start filesystem watcher for the /home directory const watcher = sandbox.filesystem.watchDir('/home') // $HighlightLine diff --git a/apps/docs/src/code/js/basics/fs_write.js b/apps/docs/src/code/js/basics/fs_write.js index 55652af73..774a36788 100644 --- a/apps/docs/src/code/js/basics/fs_write.js +++ b/apps/docs/src/code/js/basics/fs_write.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // `filesystem.write()` will: // - create the file if it doesn't exist diff --git a/apps/docs/src/code/js/basics/fs_write_bytes.js b/apps/docs/src/code/js/basics/fs_write_bytes.js index 5aac0ee62..72b61dbac 100644 --- a/apps/docs/src/code/js/basics/fs_write_bytes.js +++ b/apps/docs/src/code/js/basics/fs_write_bytes.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // Let's convert string to bytes for testing purposes const encoder = new TextEncoder('utf-8') diff --git a/apps/docs/src/code/js/basics/get_url.js b/apps/docs/src/code/js/basics/get_url.js index 820c0b01f..0372f3b6a 100644 --- a/apps/docs/src/code/js/basics/get_url.js +++ b/apps/docs/src/code/js/basics/get_url.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) const url = sandbox.getHostname() // $HighlightLine console.log('https://' + url) diff --git a/apps/docs/src/code/js/basics/get_url_port.js b/apps/docs/src/code/js/basics/get_url_port.js index e6ed2f234..007e6b2f5 100644 --- a/apps/docs/src/code/js/basics/get_url_port.js +++ b/apps/docs/src/code/js/basics/get_url_port.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) const openPort = 3000 const url = sandbox.getHostname(openPort) // $HighlightLine diff --git a/apps/docs/src/code/js/basics/process_env_vars.js b/apps/docs/src/code/js/basics/process_env_vars.js index 12f822cd2..177df9696 100644 --- a/apps/docs/src/code/js/basics/process_env_vars.js +++ b/apps/docs/src/code/js/basics/process_env_vars.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', envVars: {FOO: 'Hello'}, }) diff --git a/apps/docs/src/code/js/basics/process_exit.js b/apps/docs/src/code/js/basics/process_exit.js index 7aba32b03..0839482f2 100644 --- a/apps/docs/src/code/js/basics/process_exit.js +++ b/apps/docs/src/code/js/basics/process_exit.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', onExit: () => console.log('[sandbox]', 'process ended'), // $HighlightLine }) diff --git a/apps/docs/src/code/js/basics/process_start.js b/apps/docs/src/code/js/basics/process_start.js index 8e0e0af35..754b814a4 100644 --- a/apps/docs/src/code/js/basics/process_start.js +++ b/apps/docs/src/code/js/basics/process_start.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) const npmInit = await sandbox.process.start({ cmd: 'npm init -y', // $HighlightLine diff --git a/apps/docs/src/code/js/basics/process_stop.js b/apps/docs/src/code/js/basics/process_stop.js index 01e3c4b8e..745a23538 100644 --- a/apps/docs/src/code/js/basics/process_stop.js +++ b/apps/docs/src/code/js/basics/process_stop.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', }) const npmInit = await sandbox.process.start({ diff --git a/apps/docs/src/code/js/basics/process_stream_stderr.js b/apps/docs/src/code/js/basics/process_stream_stderr.js index 5295820fc..47b58957a 100644 --- a/apps/docs/src/code/js/basics/process_stream_stderr.js +++ b/apps/docs/src/code/js/basics/process_stream_stderr.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', }) // This command will fail and output to stderr because Golang isn't installed in the cloud playground diff --git a/apps/docs/src/code/js/basics/process_stream_stdout.js b/apps/docs/src/code/js/basics/process_stream_stdout.js index f8a17caf9..92a00c504 100644 --- a/apps/docs/src/code/js/basics/process_stream_stdout.js +++ b/apps/docs/src/code/js/basics/process_stream_stdout.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', onStdout: (output) => console.log('sandbox', output.line), // $HighlightLine }) diff --git a/apps/docs/src/code/js/basics/process_write_stdin.js b/apps/docs/src/code/js/basics/process_write_stdin.js index 87059f1f1..8e7f0cc88 100644 --- a/apps/docs/src/code/js/basics/process_write_stdin.js +++ b/apps/docs/src/code/js/basics/process_write_stdin.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // This example will print back the string we send to the process using `sendStdin()` diff --git a/apps/docs/src/code/js/basics/scan_ports.js b/apps/docs/src/code/js/basics/scan_ports.js index 4e479de1f..c004dc937 100644 --- a/apps/docs/src/code/js/basics/scan_ports.js +++ b/apps/docs/src/code/js/basics/scan_ports.js @@ -21,7 +21,7 @@ function printNewPortAndURL(openPorts, sandbox) { } const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', onScanPorts: (openPorts) => printNewPortAndURL(openPorts, sandbox), // $HighlightLine }) diff --git a/apps/docs/src/code/js/basics/set_env_vars.js b/apps/docs/src/code/js/basics/set_env_vars.js index a51fbd55e..24e17db41 100644 --- a/apps/docs/src/code/js/basics/set_env_vars.js +++ b/apps/docs/src/code/js/basics/set_env_vars.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', envVars: {FOO: 'Hello'}, // $HighlightLine }) diff --git a/apps/docs/src/code/js/basics/upload_file.js b/apps/docs/src/code/js/basics/upload_file.js index a736a2e68..65d63f015 100644 --- a/apps/docs/src/code/js/basics/upload_file.js +++ b/apps/docs/src/code/js/basics/upload_file.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' import fs from 'node:fs' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // If you're in the server environment const filename = 'data.csv' // $HighlightLine diff --git a/apps/docs/src/code/js/code_exec/process.js b/apps/docs/src/code/js/code_exec/process.js index c7fff41ea..a295d2135 100644 --- a/apps/docs/src/code/js/code_exec/process.js +++ b/apps/docs/src/code/js/code_exec/process.js @@ -3,7 +3,7 @@ import { Sandbox } from '@e2b/sdk' // 1. Start the playground sandbox const sandbox = await Sandbox.create({ // You can pass your own sandbox template id - id: 'base', + template: 'base', apiKey: process.env.E2B_API_KEY, }) diff --git a/apps/docs/src/code/js/cwd/filesystem.js b/apps/docs/src/code/js/cwd/filesystem.js index dac0b420c..9f8cf3be4 100644 --- a/apps/docs/src/code/js/cwd/filesystem.js +++ b/apps/docs/src/code/js/cwd/filesystem.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', cwd: '/home/user/code', // $HighlightLine }) diff --git a/apps/docs/src/code/js/cwd/process.js b/apps/docs/src/code/js/cwd/process.js index 98eeed2bd..fc7289e4b 100644 --- a/apps/docs/src/code/js/cwd/process.js +++ b/apps/docs/src/code/js/cwd/process.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', cwd: '/code', // $HighlightLine }) diff --git a/apps/docs/src/code/js/cwd/sandbox.js b/apps/docs/src/code/js/cwd/sandbox.js index 1e9a0da73..7141641fc 100644 --- a/apps/docs/src/code/js/cwd/sandbox.js +++ b/apps/docs/src/code/js/cwd/sandbox.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', cwd: '/code', // $HighlightLine }) diff --git a/apps/docs/src/code/js/logging/e2b_logging.js b/apps/docs/src/code/js/logging/e2b_logging.js index 87ec6ecea..1a308a3d4 100644 --- a/apps/docs/src/code/js/logging/e2b_logging.js +++ b/apps/docs/src/code/js/logging/e2b_logging.js @@ -9,7 +9,7 @@ const logger = { } const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', apiKey: process.env.E2B_API_KEY, logger, // $HighlightLine }) diff --git a/apps/docs/src/code/js/processes/background_processes.js b/apps/docs/src/code/js/processes/background_processes.js index ece37170b..0ef9d4f75 100644 --- a/apps/docs/src/code/js/processes/background_processes.js +++ b/apps/docs/src/code/js/processes/background_processes.js @@ -1,7 +1,7 @@ import { Sandbox } from '@e2b/sdk' const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', apiKey: process.env.E2B_API_KEY, }) diff --git a/apps/docs/src/code/js/quickstart.js b/apps/docs/src/code/js/quickstart.js index cbe6bbe33..4d8083918 100644 --- a/apps/docs/src/code/js/quickstart.js +++ b/apps/docs/src/code/js/quickstart.js @@ -3,7 +3,7 @@ import { Sandbox } from '@e2b/sdk' // 1. Start cloud playground const sandbox = await Sandbox.create({ // $HighlightLine - id: 'base', // or you can pass your own sandbox template id + template: 'base', // or you can pass your own sandbox template id apiKey: process.env.E2B_API_KEY, }) diff --git a/apps/docs/src/code/js/reconnect/reconnect.js b/apps/docs/src/code/js/reconnect/reconnect.js index 22fff2dcb..53134b221 100644 --- a/apps/docs/src/code/js/reconnect/reconnect.js +++ b/apps/docs/src/code/js/reconnect/reconnect.js @@ -4,7 +4,7 @@ async function wait(ms) { return new Promise(resolve => setTimeout(resolve, ms)) } -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // Do something in the sandbox await sandbox.filesystem.write('hello.txt', 'Hello World!') diff --git a/apps/docs/src/code/js/reconnect/reconnect_1.js b/apps/docs/src/code/js/reconnect/reconnect_1.js index bf8d68406..213722dec 100644 --- a/apps/docs/src/code/js/reconnect/reconnect_1.js +++ b/apps/docs/src/code/js/reconnect/reconnect_1.js @@ -4,4 +4,4 @@ async function wait(ms) { return new Promise(resolve => setTimeout(resolve, ms)) } -const sandbox = await Sandbox.create({id: 'base'}) \ No newline at end of file +const sandbox = await Sandbox.create({ template: 'base' }) \ No newline at end of file diff --git a/apps/docs/src/code/js/timeout/timeout_filesystem.js b/apps/docs/src/code/js/timeout/timeout_filesystem.js index 6cbe4b130..99ccdd21e 100644 --- a/apps/docs/src/code/js/timeout/timeout_filesystem.js +++ b/apps/docs/src/code/js/timeout/timeout_filesystem.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // Timeout 3s for the write operation await sandbox.filesystem.write('hello.txt', 'Hello World!', {timeout: 3000}) // $HighlightLine diff --git a/apps/docs/src/code/js/timeout/timeout_process.js b/apps/docs/src/code/js/timeout/timeout_process.js index 81ce58eb7..bfe3633aa 100644 --- a/apps/docs/src/code/js/timeout/timeout_process.js +++ b/apps/docs/src/code/js/timeout/timeout_process.js @@ -1,6 +1,6 @@ import { Sandbox } from '@e2b/sdk' -const sandbox = await Sandbox.create({id: 'base'}) +const sandbox = await Sandbox.create({ template: 'base' }) // Timeout 3s for the process to start const npmInit = await sandbox.process.start({ diff --git a/apps/docs/src/code/js/timeout/timeout_sandbox.js b/apps/docs/src/code/js/timeout/timeout_sandbox.js index d2bc2464e..e9e379470 100644 --- a/apps/docs/src/code/js/timeout/timeout_sandbox.js +++ b/apps/docs/src/code/js/timeout/timeout_sandbox.js @@ -2,7 +2,7 @@ import { Sandbox } from '@e2b/sdk' // Timeout 3s for the sandbox to open const sandbox = await Sandbox.create({ - id: 'base', + template: 'base', timeout: 3000, // $HighlightLine }) diff --git a/apps/docs/src/code/python/agents/clone_repo.py b/apps/docs/src/code/python/agents/clone_repo.py index 8af9823f7..835f2e29a 100644 --- a/apps/docs/src/code/python/agents/clone_repo.py +++ b/apps/docs/src/code/python/agents/clone_repo.py @@ -13,7 +13,7 @@ def main(): # 1. Start the playground sandbox sandbox = Sandbox( # Select the right runtime - id="base", + template="base", api_key=E2B_API_KEY, ) diff --git a/apps/docs/src/code/python/agents/code_exec.py b/apps/docs/src/code/python/agents/code_exec.py index 56b0eee4d..60a20d85b 100644 --- a/apps/docs/src/code/python/agents/code_exec.py +++ b/apps/docs/src/code/python/agents/code_exec.py @@ -8,7 +8,7 @@ def print_out(output): # 1. Start the playground sandbox sandbox = Sandbox( # You can pass your own sandbox template id - id="base", + template="base", ) # 2. Save the JavaScript code to a file inside the playground diff --git a/apps/docs/src/code/python/agents/start_process.py b/apps/docs/src/code/python/agents/start_process.py index 4e5ba1028..6d4838ffd 100644 --- a/apps/docs/src/code/python/agents/start_process.py +++ b/apps/docs/src/code/python/agents/start_process.py @@ -13,7 +13,7 @@ def main(): # 1. Start the playground sandbox sandbox = Sandbox( # Select the right runtime - id="base", + template="base", api_key=E2B_API_KEY, ) diff --git a/apps/docs/src/code/python/basics/download_file.py b/apps/docs/src/code/python/basics/download_file.py index a645132cc..2984ab0fb 100644 --- a/apps/docs/src/code/python/basics/download_file.py +++ b/apps/docs/src/code/python/basics/download_file.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") file_in_bytes = sandbox.download_file("path/to/remote/file/inside/sandbox") # $HighlightLine # Save file to local filesystem diff --git a/apps/docs/src/code/python/basics/fs_ls.py b/apps/docs/src/code/python/basics/fs_ls.py index b9dcd11dc..c27daba4e 100644 --- a/apps/docs/src/code/python/basics/fs_ls.py +++ b/apps/docs/src/code/python/basics/fs_ls.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # List the root directory content = sandbox.filesystem.list("/") # $HighlightLine diff --git a/apps/docs/src/code/python/basics/fs_mkdir.py b/apps/docs/src/code/python/basics/fs_mkdir.py index dd6469b36..8657f9c2d 100644 --- a/apps/docs/src/code/python/basics/fs_mkdir.py +++ b/apps/docs/src/code/python/basics/fs_mkdir.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # Create a new directory '/dir' sandbox.filesystem.make_dir("/dir") # $HighlightLine diff --git a/apps/docs/src/code/python/basics/fs_read.py b/apps/docs/src/code/python/basics/fs_read.py index 3a025204d..ea38ab74c 100644 --- a/apps/docs/src/code/python/basics/fs_read.py +++ b/apps/docs/src/code/python/basics/fs_read.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # Read the '/etc/hosts' file file_content = sandbox.filesystem.read("/etc/hosts") # $HighlightLine diff --git a/apps/docs/src/code/python/basics/fs_read_bytes.py b/apps/docs/src/code/python/basics/fs_read_bytes.py index e40387ade..ff5a50a11 100644 --- a/apps/docs/src/code/python/basics/fs_read_bytes.py +++ b/apps/docs/src/code/python/basics/fs_read_bytes.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # File bytes will read file's content as bytes # `file_bytes` as a bytearray diff --git a/apps/docs/src/code/python/basics/fs_watch.py b/apps/docs/src/code/python/basics/fs_watch.py index d7bb474f1..09c267b4f 100644 --- a/apps/docs/src/code/python/basics/fs_watch.py +++ b/apps/docs/src/code/python/basics/fs_watch.py @@ -12,7 +12,7 @@ def create_watcher(sandbox): # $HighlightLine watcher.start() # $HighlightLine -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") create_watcher(sandbox) # $HighlightLine diff --git a/apps/docs/src/code/python/basics/fs_write.py b/apps/docs/src/code/python/basics/fs_write.py index 48ffac64c..df1b869dc 100644 --- a/apps/docs/src/code/python/basics/fs_write.py +++ b/apps/docs/src/code/python/basics/fs_write.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # `filesystem.write()` will: # - create the file if it doesn't exist diff --git a/apps/docs/src/code/python/basics/fs_write_bytes.py b/apps/docs/src/code/python/basics/fs_write_bytes.py index 6f38b9ed0..762b9dc72 100644 --- a/apps/docs/src/code/python/basics/fs_write_bytes.py +++ b/apps/docs/src/code/python/basics/fs_write_bytes.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") content_in_bytes = bytearray(b"Hello world") diff --git a/apps/docs/src/code/python/basics/get_url.py b/apps/docs/src/code/python/basics/get_url.py index b425b2613..afab231d0 100644 --- a/apps/docs/src/code/python/basics/get_url.py +++ b/apps/docs/src/code/python/basics/get_url.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") url = sandbox.get_hostname() # $HighlightLine print("https://" + url) diff --git a/apps/docs/src/code/python/basics/get_url_port.py b/apps/docs/src/code/python/basics/get_url_port.py index a005e8e35..3e273eace 100644 --- a/apps/docs/src/code/python/basics/get_url_port.py +++ b/apps/docs/src/code/python/basics/get_url_port.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") open_port = 3000 url = sandbox.get_hostname(open_port) # $HighlightLine diff --git a/apps/docs/src/code/python/basics/process_env_vars.py b/apps/docs/src/code/python/basics/process_env_vars.py index b707567ee..4ae94e2b6 100644 --- a/apps/docs/src/code/python/basics/process_env_vars.py +++ b/apps/docs/src/code/python/basics/process_env_vars.py @@ -1,7 +1,7 @@ from e2b import Sandbox sandbox = Sandbox( - id="base", + template="base", env_vars={"FOO": "Hello"} ) diff --git a/apps/docs/src/code/python/basics/process_exit.py b/apps/docs/src/code/python/basics/process_exit.py index ce6e1f11c..4e1a80361 100644 --- a/apps/docs/src/code/python/basics/process_exit.py +++ b/apps/docs/src/code/python/basics/process_exit.py @@ -1,7 +1,7 @@ from e2b import Sandbox sandbox = Sandbox( - id="base", + template="base", on_exit=lambda: print("[sandbox]", "process ended"), # $HighlightLine ) diff --git a/apps/docs/src/code/python/basics/process_start.py b/apps/docs/src/code/python/basics/process_start.py index 7a38d9383..af1aae136 100644 --- a/apps/docs/src/code/python/basics/process_start.py +++ b/apps/docs/src/code/python/basics/process_start.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") npm_init = sandbox.process.start("npm init -y") # $HighlightLine npm_init.wait() diff --git a/apps/docs/src/code/python/basics/process_stop.py b/apps/docs/src/code/python/basics/process_stop.py index 072c1808f..57bcf997a 100644 --- a/apps/docs/src/code/python/basics/process_stop.py +++ b/apps/docs/src/code/python/basics/process_stop.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") npm_init = sandbox.process.start("npm init -y") npm_init.kill() # $HighlightLine diff --git a/apps/docs/src/code/python/basics/process_stream_stderr.py b/apps/docs/src/code/python/basics/process_stream_stderr.py index c40d4e445..ce25ccf00 100644 --- a/apps/docs/src/code/python/basics/process_stream_stderr.py +++ b/apps/docs/src/code/python/basics/process_stream_stderr.py @@ -1,7 +1,7 @@ from e2b import Sandbox sandbox = Sandbox( - id="base", + template="base", on_stderr=lambda output: print("[sandbox]", output.line), # $HighlightLine ) diff --git a/apps/docs/src/code/python/basics/process_stream_stdout.py b/apps/docs/src/code/python/basics/process_stream_stdout.py index 4838cafc8..07b2a6b51 100644 --- a/apps/docs/src/code/python/basics/process_stream_stdout.py +++ b/apps/docs/src/code/python/basics/process_stream_stdout.py @@ -1,7 +1,7 @@ from e2b import Sandbox sandbox = Sandbox( - id="base", + template="base", on_stdout=lambda output: print("sandbox", output.line), # $HighlightLine ) diff --git a/apps/docs/src/code/python/basics/process_write_stdin.py b/apps/docs/src/code/python/basics/process_write_stdin.py index 50c7c53b9..7786d2a7f 100644 --- a/apps/docs/src/code/python/basics/process_write_stdin.py +++ b/apps/docs/src/code/python/basics/process_write_stdin.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # This example will print back the string we send to the process using `send_stdin()` diff --git a/apps/docs/src/code/python/basics/scan_ports.py b/apps/docs/src/code/python/basics/scan_ports.py index 24433424d..023c2ba6d 100644 --- a/apps/docs/src/code/python/basics/scan_ports.py +++ b/apps/docs/src/code/python/basics/scan_ports.py @@ -23,7 +23,7 @@ def print_new_port_and_url(open_ports, sandbox): sandbox = Sandbox( - id="base", + template="base", on_scan_ports=lambda open_ports: print_new_port_and_url(open_ports, sandbox) # $HighlightLine ) diff --git a/apps/docs/src/code/python/basics/set_env_vars.py b/apps/docs/src/code/python/basics/set_env_vars.py index be3a3e004..30234e9d4 100644 --- a/apps/docs/src/code/python/basics/set_env_vars.py +++ b/apps/docs/src/code/python/basics/set_env_vars.py @@ -1,7 +1,7 @@ from e2b import Sandbox sandbox = Sandbox( - id="base", + template="base", env_vars={"FOO": "Hello"}, # $HighlightLine ) diff --git a/apps/docs/src/code/python/basics/upload_file.py b/apps/docs/src/code/python/basics/upload_file.py index c8eb0199d..4d9b3fea4 100644 --- a/apps/docs/src/code/python/basics/upload_file.py +++ b/apps/docs/src/code/python/basics/upload_file.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") with open("path/to/local/file", "rb") as f: remote_path = sandbox.upload_file(f) # $HighlightLine diff --git a/apps/docs/src/code/python/code_exec/process.py b/apps/docs/src/code/python/code_exec/process.py index bf52a6d81..840e8f56e 100644 --- a/apps/docs/src/code/python/code_exec/process.py +++ b/apps/docs/src/code/python/code_exec/process.py @@ -13,7 +13,7 @@ def main(): # 1. Start the playground sandbox sandbox = Sandbox( # You can pass your own sandbox template id - id="base", + template="base", api_key=E2B_API_KEY, ) diff --git a/apps/docs/src/code/python/cwd/filesystem.py b/apps/docs/src/code/python/cwd/filesystem.py index a80c01331..6aa0f439d 100644 --- a/apps/docs/src/code/python/cwd/filesystem.py +++ b/apps/docs/src/code/python/cwd/filesystem.py @@ -1,7 +1,7 @@ from e2b import Sandbox sandbox = Sandbox( - id="base", + template="base", cwd="/home/user/code" # $HighlightLine ) sandbox.filesystem.write("hello.txt", "Welcome to E2B!") # $HighlightLine diff --git a/apps/docs/src/code/python/cwd/process.py b/apps/docs/src/code/python/cwd/process.py index 5a512f380..ef8882107 100644 --- a/apps/docs/src/code/python/cwd/process.py +++ b/apps/docs/src/code/python/cwd/process.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base", cwd="/code") # $HighlightLine +sandbox = Sandbox(template="base", cwd="/code") # $HighlightLine sandbox_cwd = sandbox.process.start("pwd") # $HighlightLine sandbox_cwd.wait() print(sandbox_cwd.output.stdout) diff --git a/apps/docs/src/code/python/cwd/sandbox.py b/apps/docs/src/code/python/cwd/sandbox.py index 4fb8836cc..89f0f7fd5 100644 --- a/apps/docs/src/code/python/cwd/sandbox.py +++ b/apps/docs/src/code/python/cwd/sandbox.py @@ -1,7 +1,7 @@ from e2b import Sandbox sandbox = Sandbox( - id="base", + template="base", cwd="/code", # $HighlightLine ) diff --git a/apps/docs/src/code/python/logging/e2b_logging.py b/apps/docs/src/code/python/logging/e2b_logging.py index eaa36809b..6e161e597 100644 --- a/apps/docs/src/code/python/logging/e2b_logging.py +++ b/apps/docs/src/code/python/logging/e2b_logging.py @@ -30,7 +30,7 @@ def main(): - sandbox = Sandbox(id="base", api_key=E2B_API_KEY) + sandbox = Sandbox(template="base", api_key=E2B_API_KEY) sandbox.filesystem.write("test.txt", "Hello World") sandbox.close() diff --git a/apps/docs/src/code/python/processes/background_processes.py b/apps/docs/src/code/python/processes/background_processes.py index 1d78c03ff..9f95de844 100644 --- a/apps/docs/src/code/python/processes/background_processes.py +++ b/apps/docs/src/code/python/processes/background_processes.py @@ -11,7 +11,7 @@ def print_stdout(output): def main(): - sandbox = Sandbox(id="base", api_key=E2B_API_KEY) + sandbox = Sandbox(template="base", api_key=E2B_API_KEY) # Start a server process in the background # We are not using `background_server.wait()` - that would wait for the process to finish running diff --git a/apps/docs/src/code/python/timeout/timeout_filesystem.py b/apps/docs/src/code/python/timeout/timeout_filesystem.py index 85dfd28e3..943e4ff65 100644 --- a/apps/docs/src/code/python/timeout/timeout_filesystem.py +++ b/apps/docs/src/code/python/timeout/timeout_filesystem.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # Timeout 3s for the write operation sandbox.filesystem.write("test.txt", "Hello World", timeout=3) # $HighlightLine diff --git a/apps/docs/src/code/python/timeout/timeout_process.py b/apps/docs/src/code/python/timeout/timeout_process.py index 657f2c1b3..f3ff68e81 100644 --- a/apps/docs/src/code/python/timeout/timeout_process.py +++ b/apps/docs/src/code/python/timeout/timeout_process.py @@ -1,6 +1,6 @@ from e2b import Sandbox -sandbox = Sandbox(id="base") +sandbox = Sandbox(template="base") # Timeout 3s for the process to start npm_init = sandbox.process.start("npm init -y", timeout=3) # $HighlightLine diff --git a/apps/docs/src/code/python/timeout/timeout_sandbox.py b/apps/docs/src/code/python/timeout/timeout_sandbox.py index 8d3b1a2df..acd0cab5d 100644 --- a/apps/docs/src/code/python/timeout/timeout_sandbox.py +++ b/apps/docs/src/code/python/timeout/timeout_sandbox.py @@ -1,6 +1,6 @@ from e2b import Sandbox # Timeout 3s for the sandbox to open -sandbox = Sandbox(id="base", timeout=3) # $HighlightLine +sandbox = Sandbox(template="base", timeout=3) # $HighlightLine sandbox.close() diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 70fc97c60..63c036000 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -42,12 +42,12 @@ 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]', - )} and there is no ${asLocal('e2b.toml')} a new sandbox will be created`, + '[template]', + )} to rebuild it. If you don's specify ${asBold( + '[template]', + )} and there is no ${asLocal('e2b.toml')} a new sandbox template will be created`, ) .addOption(pathOption) .option( @@ -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 = template let dockerfile = opts.dockerfile let startCmd = opts.cmd @@ -104,18 +104,18 @@ export const buildCommand = new commander.Command('build') console.log( `Found sandbox template ${asFormattedSandboxTemplate( { - envID: config.id, - aliases: config.name ? [config.name] : undefined, + envID: config.template_id, + aliases: config.template_name ? [config.template_name] : undefined, }, relativeConfigPath, )}`, ) - envID = config.id + envID = config.template_id dockerfile = opts.dockerfile || config.dockerfile startCmd = opts.cmd || config.start_cmd } - if (config && id && config.id !== id) { + 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, { - id: build.envID, + template_id: build.envID, dockerfile: dockerfileRelativePath, - name, + template_name: name, start_cmd: startCmd, }, true, @@ -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/overview diff --git a/packages/cli/src/commands/delete.ts b/packages/cli/src/commands/delete.ts index 19432b848..16ece0f3e 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]', - )} the command will try delete sandbox template defined by ${asLocal('e2b.toml')}.`, + '[template]', + )} to delete it. If you don's specify ${asBold( + '[template]', + )} the command will try to 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 & { configPath?: string })[] = [] + const envs: (Pick & { configPath?: string })[] = [] - if (id) { + if (template) { envs.push({ - id, + 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 => ({ id: e.envID, ...e }))) + envs.push(...selectedEnvs.map(e => ({ template_id: 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') : undefined if (!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_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.id }, e.configPath)}`) - await deleteEnv(accessToken, { envID: e.id }) + 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 85fd62081..c28e41bbf 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 = template const 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, - aliases: config.name ? [config.name] : undefined, + envID: config.template_id, + aliases: config.template_name ? [config.template_name] : undefined, }, relativeConfigPath, )}`, ) - envID = config.id + envID = config.template_id } if (!envID) { @@ -50,9 +50,8 @@ export const shellCommand = new commander.Command('shell') ) process.exit(1) } - const template: Pick = { 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.ts index b6db2d5b2..3e16c349b 100644 --- a/packages/cli/src/config/index.ts +++ b/packages/cli/src/config/index.ts @@ -8,23 +8,68 @@ 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(), - id: 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; +interface Migration { + from: string; + to: string; +} + +// 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_id', + }, + { + from: 'name', + to: 'template_name', + }, +] + +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] + } + } + + return config +} + 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( @@ -47,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.id, + envID: config.template_id, }, configPath, )} cannot be saved: ${err.message}`, diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.ts index da54084b0..f6a0d7ce5 100644 --- a/packages/js-sdk/src/index.ts +++ b/packages/js-sdk/src/index.ts @@ -21,7 +21,6 @@ export type { ProcessManager } from './sandbox/process' export type { EnvVars } from './sandbox/envVars' export { runCode, CodeRuntime } from './runCode' // Export CodeRuntime enum as value, not as type, so it can be actually used in consumer code import { Sandbox } from './sandbox/index' -// export { runCmd } from './runCmd' import { DataAnalysis } from './templates/dataAnalysis' export { DataAnalysis as CodeInterpreter } @@ -32,5 +31,3 @@ export type { Action } from './sandbox/index' export { Sandbox } export default Sandbox - -// export { Sandbox } diff --git a/packages/js-sdk/src/runCmd.ts b/packages/js-sdk/src/runCmd.ts index aaf034045..b559b209d 100644 --- a/packages/js-sdk/src/runCmd.ts +++ b/packages/js-sdk/src/runCmd.ts @@ -2,7 +2,6 @@ import { Sandbox } from './sandbox' export async function runCmd(command: string, opts?: { apiKey?: string }) { const sandbox = await Sandbox.create({ - id: 'Bash', apiKey: opts?.apiKey || process?.env?.E2B_API_KEY || '', // Sandbox.create will throw an error if the API key is not provided so no need to check here }) diff --git a/packages/js-sdk/src/runCode.ts b/packages/js-sdk/src/runCode.ts index 2a5d57345..dae6be30a 100644 --- a/packages/js-sdk/src/runCode.ts +++ b/packages/js-sdk/src/runCode.ts @@ -58,7 +58,7 @@ export async function runCode( } const sandbox = await Sandbox.create({ - id: envID, + template: envID, apiKey: opts?.apiKey || process?.env?.E2B_API_KEY || '', // Sandbox.create will throw an error if the API key is not provided so no need to check here }) diff --git a/packages/js-sdk/src/sandbox/index.ts b/packages/js-sdk/src/sandbox/index.ts index bcfb12066..2f4bd38eb 100644 --- a/packages/js-sdk/src/sandbox/index.ts +++ b/packages/js-sdk/src/sandbox/index.ts @@ -454,15 +454,15 @@ export class Sandbox extends SandboxConnection { static async create(): Promise; /** * Creates a new Sandbox from the template with the specified ID. - * @param id Sandbox ID + * @param template Sandbox template ID or name * @returns New Sandbox * * @example * ```ts - * const sandbox = await Sandbox.create("sandboxID") + * const sandbox = await Sandbox.create("sandboxTemplateID") * ``` */ - static async create(id: string): Promise; + static async create(template: string): Promise; /** * Creates a new Sandbox from the specified options. * @param opts Sandbox options @@ -471,14 +471,14 @@ export class Sandbox extends SandboxConnection { * @example * ```ts * const sandbox = await Sandbox.create({ - * id: "sandboxID", + * template: "sandboxTemplate", * onStdout: console.log, * }) * ``` */ static async create(opts: SandboxOpts): Promise; - static async create(optsOrID?: string | SandboxOpts) { - const opts = typeof optsOrID === 'string' ? { id: optsOrID } : optsOrID + static async create(optsOrTemplate?: string | SandboxOpts) { + const opts: SandboxOpts | undefined = typeof optsOrTemplate === 'string' ? { template: optsOrTemplate } : optsOrTemplate const sandbox = new Sandbox(opts) await sandbox._open({ timeout: opts?.timeout }) diff --git a/packages/js-sdk/src/sandbox/sandboxConnection.ts b/packages/js-sdk/src/sandbox/sandboxConnection.ts index b1b06cfd4..b09c69a0c 100644 --- a/packages/js-sdk/src/sandbox/sandboxConnection.ts +++ b/packages/js-sdk/src/sandbox/sandboxConnection.ts @@ -34,6 +34,17 @@ export interface Logger { } export interface SandboxConnectionOpts { + /** + * Sandbox Template ID or name. + * + * If not specified, the 'base' template will be used. + */ + template?: string; + /** + * @deprecated Use `template` instead. + * + * Sandbox Template ID or name. + */ id?: string; apiKey?: string; cwd?: string; @@ -102,10 +113,9 @@ export class SandboxConnection { } private get templateID(): string { - return this.opts.id || 'base' + return this.opts.template || this.opts.id || 'base' } - /** * Keep the sandbox alive for the specified duration. * @@ -128,8 +138,6 @@ export class SandboxConnection { }) } - - /** * Get the hostname for the sandbox or for the specified sandbox's port. * @@ -337,93 +345,93 @@ export class SandboxConnection { private async connectRpc() { const hostname = this.getHostname(this.opts.__debug_port || ENVD_PORT) - if (!hostname) { - throw new Error('Cannot get sandbox\'s hostname') - } + if (!hostname) { + throw new Error('Cannot get sandbox\'s hostname') + } - const protocol = this.opts.__debug_devEnv === 'local' ? 'ws' : 'wss' - const sandboxURL = `${protocol}://${hostname}${WS_ROUTE}` + const protocol = this.opts.__debug_devEnv === 'local' ? 'ws' : 'wss' + const sandboxURL = `${protocol}://${hostname}${WS_ROUTE}` - this.rpc.onError((err) => { - // not warn, because this is somewhat expected behaviour during initialization - this.logger.debug?.( - `Error in WebSocket of sandbox "${this.sandbox?.instanceID}": ${err.message ?? err.code ?? err.toString() - }. Trying to reconnect...`, - ) - }) + this.rpc.onError((err) => { + // not warn, because this is somewhat expected behaviour during initialization + this.logger.debug?.( + `Error in WebSocket of sandbox "${this.sandbox?.instanceID}": ${err.message ?? err.code ?? err.toString() + }. Trying to reconnect...`, + ) + }) - let isFinished = false - let resolveOpening: (() => void) | undefined - let rejectOpening: (() => void) | undefined + let isFinished = false + let resolveOpening: (() => void) | undefined + let rejectOpening: (() => void) | undefined - const openingPromise = new Promise((resolve, reject) => { - resolveOpening = () => { - if (isFinished) return - isFinished = true - resolve() - } - rejectOpening = () => { - if (isFinished) return - isFinished = true - reject() - } - }) + const openingPromise = new Promise((resolve, reject) => { + resolveOpening = () => { + if (isFinished) return + isFinished = true + resolve() + } + rejectOpening = () => { + if (isFinished) return + isFinished = true + reject() + } + }) - this.rpc.onOpen(() => { - this.logger.debug?.( - `Connected to sandbox "${this.sandbox?.instanceID}"`, - ) - resolveOpening?.() - }) + this.rpc.onOpen(() => { + this.logger.debug?.( + `Connected to sandbox "${this.sandbox?.instanceID}"`, + ) + resolveOpening?.() + }) - this.rpc.onClose(async () => { + this.rpc.onClose(async () => { + this.logger.debug?.( + `Closing WebSocket connection to sandbox "${this.sandbox?.instanceID}"`, + ) + if (this.isOpen) { + await wait(WS_RECONNECT_INTERVAL) this.logger.debug?.( - `Closing WebSocket connection to sandbox "${this.sandbox?.instanceID}"`, + `Reconnecting to sandbox "${this.sandbox?.instanceID}"`, ) - if (this.isOpen) { - await wait(WS_RECONNECT_INTERVAL) + try { + // When the WS connection closes the subscribers in devbookd are removed. + // We want to delete the subscriber handlers here so there are no orphans. + this.subscribers = [] + await this.rpc.connect(sandboxURL) this.logger.debug?.( - `Reconnecting to sandbox "${this.sandbox?.instanceID}"`, + `Reconnected to sandbox "${this.sandbox?.instanceID}"`, + ) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (err: any) { + // not warn, because this is somewhat expected behaviour during initialization + this.logger.debug?.( + `Failed reconnecting to sandbox "${this.sandbox?.instanceID}": ${err.message ?? err.code ?? err.toString() + }`, ) - try { - // When the WS connection closes the subscribers in devbookd are removed. - // We want to delete the subscriber handlers here so there are no orphans. - this.subscribers = [] - await this.rpc.connect(sandboxURL) - this.logger.debug?.( - `Reconnected to sandbox "${this.sandbox?.instanceID}"`, - ) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (err: any) { - // not warn, because this is somewhat expected behaviour during initialization - this.logger.debug?.( - `Failed reconnecting to sandbox "${this.sandbox?.instanceID}": ${err.message ?? err.code ?? err.toString() - }`, - ) - } - } else { - rejectOpening?.() } - }) - - this.rpc.onNotification.push(this.handleNotification.bind(this)) + } else { + rejectOpening?.() + } + }) - try { - this.logger.debug?.( - `Connection to sandbox "${this.sandbox?.instanceID}"`, - ) - await this.rpc.connect(sandboxURL) + this.rpc.onNotification.push(this.handleNotification.bind(this)) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (err: any) { - // not warn, because this is somewhat expected behaviour during initialization - this.logger.debug?.( - `Error connecting to sandbox "${this.sandbox?.instanceID}": ${err.message ?? err.code ?? err.toString() - }`, - ) - } + try { + this.logger.debug?.( + `Connection to sandbox "${this.sandbox?.instanceID}"`, + ) + await this.rpc.connect(sandboxURL) + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (err: any) { + // not warn, because this is somewhat expected behaviour during initialization + this.logger.debug?.( + `Error connecting to sandbox "${this.sandbox?.instanceID}": ${err.message ?? err.code ?? err.toString() + }`, + ) + } - await openingPromise + await openingPromise } private handleNotification(data: IRpcNotification) { this.logger.debug?.('Handling notification:', data) diff --git a/packages/js-sdk/src/templates/dataAnalysis.ts b/packages/js-sdk/src/templates/dataAnalysis.ts index df36ed6ef..998ee295d 100644 --- a/packages/js-sdk/src/templates/dataAnalysis.ts +++ b/packages/js-sdk/src/templates/dataAnalysis.ts @@ -20,15 +20,15 @@ export interface RunPythonOpts extends Omit { onArtifact?: (artifact: Artifact) => Promise | void; } -const DataAnalysisEnvId = 'Python3-DataAnalysis' - export class DataAnalysis extends Sandbox { - constructor(opts: Omit) { - super({ id: DataAnalysisEnvId, ...opts }) + private static template = 'Python3-DataAnalysis' + + constructor(opts: Omit) { + super({ template: DataAnalysis.template, ...opts }) } static override async create(): Promise; - static override async create(opts?: Omit) { + static override async create(opts?: Omit) { const sandbox = new DataAnalysis({ ...opts }) await sandbox._open({ timeout: opts?.timeout }) diff --git a/packages/python-sdk/e2b/sandbox/main.py b/packages/python-sdk/e2b/sandbox/main.py index d94dc01fb..5b8a1216e 100644 --- a/packages/python-sdk/e2b/sandbox/main.py +++ b/packages/python-sdk/e2b/sandbox/main.py @@ -56,7 +56,8 @@ def filesystem(self) -> FilesystemManager: def __init__( self, - id: str = "base", + template: str = "base", + id: Optional[str] = None, api_key: Optional[str] = None, cwd: Optional[str] = None, env_vars: Optional[EnvVars] = None, @@ -73,11 +74,13 @@ def __init__( """ Create a new cloud sandbox. - :param id: ID of the sandbox template or the name of prepared template. + :param id: [Deprecated] Use `template` param instead. + :param template: ID of the sandbox template or the name of prepared template. If not specified a 'base' template will be used. Can be one of the following premade sandbox templates or a custom sandbox template ID: - `base` - A basic sandbox with a Linux environment - `Python3-DataAnalysis` - A Python3 sandbox with data analysis tools + :param api_key: The API key to use, if not provided, the `E2B_API_KEY` environment variable is used :param cwd: The current working directory to use :param on_scan_ports: A callback to handle opened ports @@ -87,7 +90,14 @@ def __init__( :param timeout: Timeout for sandbox to initialize in seconds, default is 60 seconds """ - logger.info(f"Creating sandbox {id if isinstance(id, str) else type(id)}") + template = id or template or "base" + + if id: + logger.warning("The id parameter is deprecated, use template instead.") + + logger.info( + f"Creating sandbox {template if isinstance(template, str) else type(template)}" + ) if cwd and cwd.startswith("~"): cwd = cwd.replace("~", "/home/user") @@ -105,7 +115,7 @@ def __init__( on_exit=on_exit, ) super().__init__( - id=id, + template=template, api_key=api_key, cwd=cwd, env_vars=env_vars, @@ -212,10 +222,10 @@ def _open(self, timeout: Optional[float] = TIMEOUT) -> None: :param timeout: Specify the duration, in seconds to give the method to finish its execution before it times out (default is 60 seconds). If set to None, the method will continue to wait until it completes, regardless of time """ - logger.info(f"Opening sandbox {self._id}") + logger.info(f"Opening sandbox {self._template}") super()._open(timeout=timeout) self._code_snippet._subscribe() - logger.info(f"Sandbox {self._id} opened") + logger.info(f"Sandbox {self._template} opened") if self.cwd: self.filesystem.make_dir(self.cwd) self._handle_start_cmd_logs() diff --git a/packages/python-sdk/e2b/sandbox/run_code.py b/packages/python-sdk/e2b/sandbox/run_code.py index e181f3c3d..993255abb 100644 --- a/packages/python-sdk/e2b/sandbox/run_code.py +++ b/packages/python-sdk/e2b/sandbox/run_code.py @@ -55,7 +55,7 @@ def run_code( f'Invalid runtime "{runtime}". Please contact us (hello@e2b.dev) if you need support for this runtime' ) - sandbox = Sandbox(id=env_id, api_key=api_key) + sandbox = Sandbox(template=env_id, api_key=api_key) sandbox.filesystem.write(filepath, code) proc = sandbox.process.start(cmd=f"{binary} {filepath}") diff --git a/packages/python-sdk/e2b/sandbox/sandbox_connection.py b/packages/python-sdk/e2b/sandbox/sandbox_connection.py index bb17e7800..cf8d52636 100644 --- a/packages/python-sdk/e2b/sandbox/sandbox_connection.py +++ b/packages/python-sdk/e2b/sandbox/sandbox_connection.py @@ -68,7 +68,7 @@ def is_open(self) -> bool: def __init__( self, - id: str, + template: str, api_key: Optional[str] = None, cwd: Optional[str] = None, env_vars: Optional[EnvVars] = None, @@ -87,7 +87,7 @@ def __init__( self.cwd = cwd self.env_vars = env_vars or {} - self._id = id + self._template = template self._api_key = api_key self._debug_hostname = _debug_hostname self._debug_port = _debug_port @@ -101,7 +101,7 @@ def __init__( self._rpc: Optional[SandboxRpc] = None self._finished = DeferredFuture(self._process_cleanup) - logger.info(f"Sandbox for template {self._id} initialized") + logger.info(f"Sandbox for template {self._template} initialized") self._open(timeout=timeout) @@ -217,7 +217,7 @@ def _open(self, timeout: Optional[float] = TIMEOUT) -> None: api = client.InstancesApi(api_client) self._sandbox = api.instances_post( - models.NewInstance(envID=self._id), + models.NewInstance(envID=self._template), _request_timeout=timeout, ) logger.info( diff --git a/packages/python-sdk/e2b/templates/data_analysis.py b/packages/python-sdk/e2b/templates/data_analysis.py index 421598cde..59ea57520 100644 --- a/packages/python-sdk/e2b/templates/data_analysis.py +++ b/packages/python-sdk/e2b/templates/data_analysis.py @@ -27,7 +27,7 @@ def download(self) -> bytes: class DataAnalysis(Sandbox): - env_id = "Python3-DataAnalysis" + template = "Python3-DataAnalysis" def __init__( self, @@ -43,7 +43,7 @@ def __init__( ): self.on_artifact = on_artifact super().__init__( - id=self.env_id, + template=self.template, api_key=api_key, cwd=cwd, env_vars=env_vars,