> ## Documentation Index
> Fetch the complete documentation index at: https://e2b-mintlify-changelog-1777288200.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK v2 migration guide

This guide helps you migrate from E2B SDK v1 to v2, covering all breaking changes and new patterns.

## Table of contents

SDK v2 introduces several important changes:

* [**New creation pattern in Python Synchronous SDK**](#1-sandbox-creation-in-synchronous-python-sdk)
* [**Secure by default**](#2-secure-communication-by-default)
* [**Updated file operations in Python SDK**](#3-file-writing-in-python-sdk)
* [**Updated list method**](#4-listing-sandboxes)

## Breaking changes

### 1. Sandbox creation in synchronous Python SDK

In v2, the synchronous Python SDK uses a class method `create()` instead of the constructor `Sandbox()`.

<CodeGroup>
  ```python Python theme={null}
  from e2b_code_interpreter import Sandbox

  sandbox = Sandbox.create()
  sandbox = Sandbox.create(template="base")
  ```
</CodeGroup>

In the v1, you would instantiate directly:

<CodeGroup>
  ```python Python theme={null}
  from e2b_code_interpreter import Sandbox

  sandbox = Sandbox()
  sandbox = Sandbox(template="base")
  ```
</CodeGroup>

### 2. Secure communication by default

Sandboxes are now **secure by default**. This means you can't access the sandbox controller directly through its URL without an authentication header.
The SDK automatically handles the authentication header for you.

For custom templates created before envd `v0.2.0`, you need to rebuild them to enable secure communication.
Otherwise, you will receive error messages when creating sandboxes. You can check the template envd version using the `e2b template list` command or view the templates list in the dashboard.

You can temporarily disable secure communication by setting `secure` to `false` during sandbox creation, but this is not recommended for production environments.

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

  const sandbox = await Sandbox.create({ secure: false }) // Explicitly disable
  ```

  ```python Python theme={null}
  from e2b_code_interpreter import Sandbox

  sandbox = Sandbox.create(secure=False)  # Explicitly disable
  ```
</CodeGroup>

Check more details in the [secured access documentation](/docs/sandbox/secured-access).

### 3. File writing in Python SDK

The file writing API in Python has been made more consistent.

In v2, use `sandbox.files.write()` for single files and `sandbox.files.write_files()` for multiple files:

<CodeGroup>
  ```python v2 theme={null}
  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"}
  ])
  ```
</CodeGroup>

In v1, the same `write()` method was overloaded for both single and multiple files:

<CodeGroup>
  ```python v1 theme={null}
  from e2b_code_interpreter import Sandbox

  sandbox = Sandbox.create()

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

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

### 4. Listing sandboxes

The method for listing sandboxes has been updated to use pagination.

<CodeGroup>
  ```js JavaScript & TypeScript theme={null}
  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)
  }

  // Iterate through 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 Python theme={null}
  from e2b_code_interpreter import Sandbox, SandboxQuery

  # Get paginator
  paginator = Sandbox.list()

  # Iterate through all sandboxes
  while paginator.has_next:
      sandboxes = paginator.next_items()
      print(sandboxes)

  # With query
  paginator = Sandbox.list(query=SandboxQuery(metadata={"key": "value"}))
  ```
</CodeGroup>
