Skip to content

SDK v2 Migration Guide

Guide for migrating from E2B SDK v1 to v2.

Breaking Changes

1. Sandbox Creation in Synchronous Python SDK

v2 Pattern (NEW):

python
from e2b_code_interpreter import Sandbox

sandbox = Sandbox.create()
sandbox = Sandbox.create(template="base")

v1 Pattern (OLD):

python
from e2b_code_interpreter import Sandbox

sandbox = Sandbox()
sandbox = Sandbox(template="base")

2. Secure Communication by Default

Sandboxes are now secure by default. Cannot access sandbox controller directly through URL without authentication header. SDK automatically handles authentication header.

Requirements:

  • Custom templates created before envd v0.2.0 must be rebuilt
  • Check template envd version: e2b template list or dashboard
  • Can temporarily disable (NOT recommended for production):
    javascript
    import { Sandbox } from '@e2b/code-interpreter'
    const sandbox = await Sandbox.create({ secure: false })

See: Secured Access Documentation

3. File Writing in Python SDK

v2 Pattern (NEW):

python
from e2b_code_interpreter import Sandbox

sandbox = Sandbox.create()

# Write single file
info = sandbox.files.write("/tmp/file.txt", "content")

# Write multiple files
infos = sandbox.files.write_files([
    {"path": "/tmp/file1.txt", "data": "content1"},
    {"path": "/tmp/file2.txt", "data": "content2"}
])

v1 Pattern (OLD):

python
# Write single file
info = sandbox.write(path="/tmp/file.txt", data="content")

# Write multiple files (same method)
infos = sandbox.write([
    {"path": "/tmp/file1.txt", "data": "content1"},
    {"path": "/tmp/file2.txt", "data": "content2"}
])

4. Listing Sandboxes

v2 Pattern (NEW) - Uses Pagination:

javascript
import { Sandbox, SandboxInfo } from '@e2b/code-interpreter'

// Get paginator
const paginator = Sandbox.list()

// Iterate through all sandboxes
for (const sandbox of await paginator.nextItems()) {
    console.log(sandbox.sandboxId)
}

// Collect all sandboxes
const allSandboxes: SandboxInfo[] = []
while (paginator.hasNext) {
    const items = await paginator.nextItems()
    allSandboxes.push(...items)
}

// With query
const queryPaginator = Sandbox.list({query: {metadata: {key: "value"}}})

Python Example:

python
from e2b_code_interpreter import Sandbox

# Get paginator
paginator = Sandbox.list()

# Iterate through all sandboxes
for sandbox in paginator.next_items():
    print(sandbox.sandbox_id)

# With query
query_paginator = Sandbox.list(query={"metadata": {"key": "value"}})

E2B Documentation • Generated from e2b.dev/docs