Skip to content

Commit

Permalink
Deprecate id parameter when spawning Sandbox and add template p…
Browse files Browse the repository at this point in the history
…arameter instead (#233)
  • Loading branch information
ValentaTomas authored Nov 24, 2023
2 parents d487184 + eeeacf1 commit 71a5ec6
Show file tree
Hide file tree
Showing 90 changed files with 314 additions and 246 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-zebras-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@e2b/cli": patch
---

Update template naming field when using CLI
6 changes: 6 additions & 0 deletions .changeset/nasty-poets-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@e2b/python-sdk": patch
"@e2b/sdk": patch
---

Deprecate id Sandbox parameter and add template parameter
14 changes: 7 additions & 7 deletions apps/docs/src/app/cli/commands/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ e2b build
```

<Note>
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.
</Note>

#### **Arguments**

<Options>
<Option type="[id]">
<Option type="[template]">
Specify the template you want to rebuild. You can use the template name or ID.
</Option>
</Options>
Expand Down Expand Up @@ -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.
Expand All @@ -81,13 +81,13 @@ e2b delete
```

<Note>
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.
</Note>

#### **Arguments**

<Options>
<Option type="[id]">
<Option type="[template]">
Specify the template you want to delete. You can use the template name or ID.
</Option>
</Options>
Expand Down Expand Up @@ -150,13 +150,13 @@ e2b shell
```

<Note>
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.
</Note>

#### **Arguments**

<Options>
<Option type="[id]" name="template-name-or-id">
<Option type="[template]">
Specify the template you want to spawn sandbox from. You can use the template name or ID.
</Option>
</Options>
Expand Down
10 changes: 5 additions & 5 deletions apps/docs/src/app/guide/custom-sandbox/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
id = "1wdqsf9le9gk21ztb4mo"
template_id = "1wdqsf9le9gk21ztb4mo"
dockerfile = "e2b.Dockerfile"
name = "my-agent-sandbox"
template_name = "my-agent-sandbox"
```
</CodeGroup>
Expand All @@ -153,15 +153,15 @@ 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.
<CodeGroup title="Spawn & control your custom sandbox" isRunnable={true}>
```js {{ language: 'js' }}
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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/app/sandbox/custom/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<sandbox-template-id>', // You get sandbox ID from the CLI after you run `$ e2b build`
template: '<sandbox-template-id>', // You get sandbox template ID from the CLI after you run `$ e2b build`
})

// Close sandbox once done
Expand All @@ -32,7 +32,7 @@ Once you build your custom sandbox template, you can spawn multiple isolated san

# Create new sandbox
sandbox = Sandbox(
id="<sandbox-template-id>", # You get sandbox ID from the CLI after you run `$ e2b build`
template="<sandbox-template>", # You get sandbox template from the CLI after you run `$ e2b build`
)

# Close sandbox once done
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/src/app/sandbox/templates/overview/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<sandbox-template-id>', // $HighlightLine
// You get sandbox template from the CLI after you run `$ e2b build`
template: '<sandbox-template>', // $HighlightLine
})

// Close sandbox once done
Expand All @@ -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="<sandbox-template-id>", # $HighlightLine
# You get sandbox template from the CLI after you run `$ e2b build`
template="<sandbox-template>", # $HighlightLine
)

# Close sandbox once done
Expand Down
5 changes: 2 additions & 3 deletions apps/docs/src/app/sandbox/templates/premade/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To get your started quickly, we offer two premade sandboxes.
Template File
</Link>
<div className="pr-1 w-[320px] flex items-center justify-start space-x-2 border border-gray-600 rounded">
<span className="font-mono text-sm w-8 h-8 flex items-center justify-center border-r border-gray-600">id</span>
<span className="font-mono text-sm w-8 h-8 flex items-center justify-center border-r border-gray-600">template</span>
<span className="font-mono text-sm text-gray-200">base</span>
</div>

Expand Down Expand Up @@ -49,7 +49,7 @@ The base sandbox has all the features of the [Sandbox API](/sandbox/api/envs) av
</Link>

<div className="pr-1 w-[320px] flex items-center justify-start space-x-2 border border-gray-600 rounded">
<span className="font-mono text-sm w-8 h-8 flex items-center justify-center border-r border-gray-600">id</span>
<span className="font-mono text-sm w-8 h-8 flex items-center justify-center border-r border-gray-600">template</span>
<span className="font-mono text-sm text-gray-200">Python3-CodeInterpreter</span>
</div>

Expand Down Expand Up @@ -201,4 +201,3 @@ sandbox.close()
- Stream code errors
- Upload file
- Download file */}

4 changes: 2 additions & 2 deletions apps/docs/src/app/sandbox/templates/start-cmd/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ The start command is specified inside the `e2b.toml` in the same directory where
<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 = "<your-start-command>" # $HighlightLine
```
</CodeGroup>
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/agents/clone_repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/agents/code_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/agents/install_deps_npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/agents/start_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/download_file.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/fs_ls.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/fs_mkdir.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/fs_read.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/fs_read_bytes.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/fs_watch.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/fs_write.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/fs_write_bytes.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/get_url.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/get_url_port.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/process_env_vars.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sandbox } from '@e2b/sdk'

const sandbox = await Sandbox.create({
id: 'base',
template: 'base',
envVars: {FOO: 'Hello'},
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/process_exit.js
Original file line number Diff line number Diff line change
@@ -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
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/process_start.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/process_stop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sandbox } from '@e2b/sdk'

const sandbox = await Sandbox.create({
id: 'base',
template: 'base',
})

const npmInit = await sandbox.process.start({
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/process_stream_stderr.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/process_stream_stdout.js
Original file line number Diff line number Diff line change
@@ -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
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/process_write_stdin.js
Original file line number Diff line number Diff line change
@@ -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()`

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/scan_ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function printNewPortAndURL(openPorts, sandbox) {
}

const sandbox = await Sandbox.create({
id: 'base',
template: 'base',
onScanPorts: (openPorts) => printNewPortAndURL(openPorts, sandbox), // $HighlightLine
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/set_env_vars.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sandbox } from '@e2b/sdk'

const sandbox = await Sandbox.create({
id: 'base',
template: 'base',
envVars: {FOO: 'Hello'}, // $HighlightLine
})

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/code/js/basics/upload_file.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

1 comment on commit 71a5ec6

@vercel
Copy link

@vercel vercel bot commented on 71a5ec6 Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

e2b-docs – ./apps/docs

e2b-docs-e2b.vercel.app
e2b-docs-git-main-e2b.vercel.app
e2b-docs.vercel.app

Please sign in to comment.