Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"group": "Sandbox",
"pages": [
"docs/sandbox",
"docs/sandbox/lifecycle",
"docs/sandbox/lifecycle-events-api",
"docs/sandbox/lifecycle-events-webhooks",
"docs/sandbox/persistence",
Expand Down
184 changes: 59 additions & 125 deletions docs/sandbox.mdx
Original file line number Diff line number Diff line change
@@ -1,141 +1,75 @@
---
title: "Sandbox lifecycle"
sidebarTitle: Lifecycle
title: "Sandbox overview"
sidebarTitle: Overview
description: "Secure runtime environments for AI agents"
---

When you start the sandbox, it stays alive for 5 minutes by default but you can change it by passing the `timeout` parameter.
After the time passes, the sandbox will be automatically shutdown.
A sandbox is an agentic runtime which is an isolated cloud VM under the hood. Sandboxes can start in as little as **~100ms**. Each sandbox has its own [filesystem](/docs/filesystem), can start [processes](/docs/commands), and has internet access with [configurable firewall](/docs/sandbox/internet-access#fine-grained-network-control).

Check warning on line 7 in docs/sandbox.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox.mdx#L7

Did you really mean 'agentic'?

<Warning>
The maximum time sandbox can be kept running without being paused is
- 24 hours on the Pro Tier
- 1 hour on the Base Tier

For more details, please refer to [sandbox persistance page](/docs/sandbox/persistence#limitations-while-in-beta).
</Warning>

<CodeGroup>
```js JavaScript & TypeScript highlight={6}
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
// 🚨 Note: The units are milliseconds.
const sandbox = await Sandbox.create({
timeoutMs: 60_000,
})
```
```python Python highlight={6}
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
# 🚨 Note: The units are seconds.
sandbox = Sandbox.create(
timeout=60,
)
```
</CodeGroup>


## Change sandbox timeout during runtime

You can change the sandbox timeout when it's running by calling the `setTimeout` method in JavaScript or `set_timeout` method in Python.

When you call the set timeout method, the sandbox timeout will be reset to the new value that you specified.

This can be useful if you want to extend the sandbox lifetime when it's already running.
You can for example start with a sandbox with 1 minute timeout and then periodically call set timeout every time user interacts with it in your app.
Sandboxes are designed to run thousands of AI agents safely with access to the real-world tools as on your own computer.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

// Change the sandbox timeout to 30 seconds.
// 🚨 The new timeout will be 30 seconds from now.
await sandbox.setTimeout(30_000)
const sbx = await Sandbox.create()
const result = await sbx.runCode('1 + 1')
console.log(result.text) // 2
await sbx.kill()
```
```python Python
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
sandbox = Sandbox.create(timeout=60)

# Change the sandbox timeout to 30 seconds.
# 🚨 The new timeout will be 30 seconds from now.
sandbox.set_timeout(30)
sbx = Sandbox.create()
result = sbx.run_code('1 + 1')
print(result.text) # 2
sbx.kill()
```
</CodeGroup>

## Retrieve sandbox information

You can retrieve sandbox information like sandbox ID, template, metadata, started at/end at date by calling the `getInfo` method in JavaScript or `get_info` method in Python.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

// Retrieve sandbox information.
const info = await sandbox.getInfo()

console.log(info)

// {
// "sandboxId": "iiny0783cype8gmoawzmx-ce30bc46",
// "templateId": "rki5dems9wqfm4r03t7g",
// "name": "base",
// "metadata": {},
// "startedAt": "2025-03-24T15:37:58.076Z",
// "endAt": "2025-03-24T15:42:58.076Z"
// }
```

```python Python
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
sandbox = Sandbox.create(timeout=60)

# Retrieve sandbox information.
info = sandbox.get_info()

print(info)

# SandboxInfo(sandbox_id='ig6f1yt6idvxkxl562scj-419ff533',
# template_id='u7nqkmpn3jjf1tvftlsu',
# name='base',
# metadata={},
# started_at=datetime.datetime(2025, 3, 24, 15, 42, 59, 255612, tzinfo=tzutc()),
# end_at=datetime.datetime(2025, 3, 24, 15, 47, 59, 255612, tzinfo=tzutc())
# )
```
</CodeGroup>

## Shutdown sandbox

You can shutdown the sandbox any time even before the timeout is up by calling the `kill` method.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

// Shutdown the sandbox immediately.
await sandbox.kill()
```
```python Python
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
sandbox = Sandbox.create(timeout=60)

# Shutdown the sandbox immediately.
sandbox.kill()
```
</CodeGroup>
## Key features

<CardGroup cols={2}>
<Card title="Filesystem" icon="folder-tree" href="/docs/filesystem">
Read, write, upload, and download files
</Card>
<Card title="Commands" icon="terminal" href="/docs/commands">
Run shell commands and start processes
</Card>
<Card title="Lifecycle" icon="hourglass" href="/docs/sandbox/lifecycle">
Manage timeout, get info, and shutdown
</Card>
<Card title="Persistence" icon="rotate-reverse" href="/docs/sandbox/persistence">
Pause and resume sandboxes with full state
</Card>
</CardGroup>

## Default configuration

| Property | Value |
|----------|-------|
| vCPUs | 2 |

Check warning on line 51 in docs/sandbox.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox.mdx#L51

Did you really mean 'vCPUs'?
| RAM | 2 GiB |
| Storage | 22 GiB |
| Internet | Enabled |

<Note>
These are defaults for the [code-interpreter](https://github.com/e2b-dev/code-interpreter) template. [Custom templates](/docs/template/quickstart) can have different CPU/RAM configurations.
</Note>

See [lifecycle](/docs/sandbox/lifecycle) for timeout configuration.

## Sandbox capabilities

| Capability | Description |
|------------|-------------|
| [Run code](/docs/code-interpreting/analyze-data-with-ai) | Execute Python, JavaScript, R, Java, Bash |
| [Filesystem](/docs/filesystem) | Full read/write access to isolated filesystem |
| [Commands](/docs/commands) | Run any shell command or process |
| [Internet](/docs/sandbox/internet-access) | Outbound HTTP/HTTPS requests |
| [Persistence](/docs/sandbox/persistence) | Pause/resume with full memory state |
| [Metadata](/docs/sandbox/metadata) | Attach custom key-value data |
| [Environment variables](/docs/sandbox/environment-variables) | Pass secrets and configuration |
| [Webhooks](/docs/sandbox/lifecycle-events-webhooks) | Get notified on lifecycle events |

For pricing details, see [Billing](/docs/billing).
141 changes: 141 additions & 0 deletions docs/sandbox/lifecycle.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: "Sandbox lifecycle"
sidebarTitle: Lifecycle
---

When you start the sandbox, it stays alive for 5 minutes by default but you can change it by passing the `timeout` parameter.
After the time passes, the sandbox will be automatically shutdown.

<Warning>
The maximum time sandbox can be kept running without being paused is
- 24 hours on the Pro Tier
- 1 hour on the Base Tier

For more details, please refer to [sandbox persistance page](/docs/sandbox/persistence#limitations-while-in-beta).
</Warning>

<CodeGroup>
```js JavaScript & TypeScript highlight={6}
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
// 🚨 Note: The units are milliseconds.
const sandbox = await Sandbox.create({
timeoutMs: 60_000,
})
```
```python Python highlight={6}
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
# 🚨 Note: The units are seconds.
sandbox = Sandbox.create(
timeout=60,
)
```
</CodeGroup>


## Change sandbox timeout during runtime

You can change the sandbox timeout when it's running by calling the `setTimeout` method in JavaScript or `set_timeout` method in Python.

When you call the set timeout method, the sandbox timeout will be reset to the new value that you specified.

This can be useful if you want to extend the sandbox lifetime when it's already running.
You can for example start with a sandbox with 1 minute timeout and then periodically call set timeout every time user interacts with it in your app.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

// Change the sandbox timeout to 30 seconds.
// 🚨 The new timeout will be 30 seconds from now.
await sandbox.setTimeout(30_000)
```
```python Python
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
sandbox = Sandbox.create(timeout=60)

# Change the sandbox timeout to 30 seconds.
# 🚨 The new timeout will be 30 seconds from now.
sandbox.set_timeout(30)
```
</CodeGroup>

## Retrieve sandbox information

You can retrieve sandbox information like sandbox ID, template, metadata, started at/end at date by calling the `getInfo` method in JavaScript or `get_info` method in Python.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

// Retrieve sandbox information.
const info = await sandbox.getInfo()

console.log(info)

// {
// "sandboxId": "iiny0783cype8gmoawzmx-ce30bc46",
// "templateId": "rki5dems9wqfm4r03t7g",
// "name": "base",
// "metadata": {},
// "startedAt": "2025-03-24T15:37:58.076Z",
// "endAt": "2025-03-24T15:42:58.076Z"
// }
```

```python Python
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
sandbox = Sandbox.create(timeout=60)

# Retrieve sandbox information.
info = sandbox.get_info()

print(info)

# SandboxInfo(sandbox_id='ig6f1yt6idvxkxl562scj-419ff533',
# template_id='u7nqkmpn3jjf1tvftlsu',
# name='base',
# metadata={},
# started_at=datetime.datetime(2025, 3, 24, 15, 42, 59, 255612, tzinfo=tzutc()),
# end_at=datetime.datetime(2025, 3, 24, 15, 47, 59, 255612, tzinfo=tzutc())
# )
```
</CodeGroup>

## Shutdown sandbox

You can shutdown the sandbox any time even before the timeout is up by calling the `kill` method.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with and keep it running for 60 seconds.
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

// Shutdown the sandbox immediately.
await sandbox.kill()
```
```python Python
from e2b_code_interpreter import Sandbox

# Create sandbox with and keep it running for 60 seconds.
sandbox = Sandbox.create(timeout=60)

# Shutdown the sandbox immediately.
sandbox.kill()
```
</CodeGroup>
6 changes: 3 additions & 3 deletions snippets/Concepts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ export const Concepts = () => {
const concepts = [
{
href: "/docs/sandbox",
title: "Sandbox lifecycle",
title: "Sandbox",
description:
"Learn about how to start the sandbox, manage its lifecycle, and interact with it.",
icon: "hourglass",
"Learn about sandboxes - isolated cloud VMs for running AI-generated code.",
icon: "box",
},
{
href: "/docs/sandbox/persistence",
Expand Down