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

# SDK client

> Create a custom client with options

The top-level `Sandbox`, `Volume`, `Template`, and `Secret` exports read their configuration from the environment variables (`E2B_API_KEY`, `E2B_DOMAIN`, …). If you need an explicit configuration — for example several API keys, teams, or [BYOC or self-hosted deployments](https://docs.e2b.dev/byoc.md) in a single process — create an `E2B` client and use the resources it exposes.

> [!NOTE]
>
> Per-call options take precedence over the client's options, which take precedence over the environment variables.

```js JavaScript & TypeScript theme={"theme":"css-variables"}
import { E2B } from 'e2b'

const client = new E2B({ apiKey: 'YOUR_API_KEY', domain: 'e2b.app' })

const sandbox = await client.Sandbox.create()
const result = await sandbox.commands.run('echo "Hello from E2B!"')
console.log(result.stdout) // Hello from E2B!
```

```python Python theme={"theme":"css-variables"}
from e2b import E2B

client = E2B(api_key="YOUR_API_KEY", domain="e2b.app")

sandbox = client.Sandbox.create()
result = sandbox.commands.run('echo "Hello from E2B!"')
print(result.stdout)  # Hello from E2B!
```

```python Python (async) theme={"theme":"css-variables"}
from e2b import E2B

client = E2B(api_key="YOUR_API_KEY", domain="e2b.app")

sandbox = await client.AsyncSandbox.create()
result = await sandbox.commands.run('echo "Hello from E2B!"')
print(result.stdout)  # Hello from E2B!
```

The [Code Interpreter](https://docs.e2b.dev/code-interpreting/analyze-data-with-ai) and [Desktop](https://docs.e2b.dev/use-cases/computer-use.md) SDKs export the same client from their own package entrypoint, with the package's `Sandbox` bound to it instead of the core one.

```js JavaScript & TypeScript theme={"theme":"css-variables"}
import { E2B } from '@e2b/code-interpreter'
import { E2B } from '@e2b/desktop'
```

```python Python theme={"theme":"css-variables"}
from e2b_code_interpreter import E2B
from e2b_desktop import E2B
```

The classes exposed by the client behave exactly like the top-level exports of the same name — only the defaults change. You can also destructure them and use them as usual.

```js JavaScript & TypeScript theme={"theme":"css-variables"}
const { Sandbox, Volume, Template, Secret } = new E2B({ apiKey: 'YOUR_API_KEY' })

const sandbox = await Sandbox.create()
const volume = await Volume.create('my-volume')
const exists = await Template.exists('my-template')
await Secret.create('openai-api-key', 'sk-***')
```

```python Python theme={"theme":"css-variables"}
client = E2B(api_key="YOUR_API_KEY")
Sandbox, Volume, Template, Secret = (
    client.Sandbox,
    client.Volume,
    client.Template,
    client.Secret,
)

sandbox = Sandbox.create()
volume = Volume.create("my-volume")
exists = Template.exists("my-template")
Secret.create("openai-api-key", "sk-***")
```

```python Python (async) theme={"theme":"css-variables"}
client = E2B(api_key="YOUR_API_KEY")
Sandbox, Volume, Template, Secret = (
    client.AsyncSandbox,
    client.AsyncVolume,
    client.AsyncTemplate,
    client.AsyncSecret,
)

sandbox = await Sandbox.create()
volume = await Volume.create("my-volume")
exists = await Template.exists("my-template")
await Secret.create("openai-api-key", "sk-***")
```

## Client options

The client accepts the same options as the individual SDK calls, for example `apiKey`/`api_key`, `domain`, `requestTimeoutMs`/`request_timeout`, `proxy`, `apiHeaders`/`api_headers`, and `logger` (JavaScript only).

In JavaScript, the only exception is `signal`: it cancels a single in-flight request, so it can only be passed per call.

## Multiple clients

Clients are isolated from each other and from the env-configured top-level exports, so you can use as many of them side by side as you need.

```js JavaScript & TypeScript theme={"theme":"css-variables"}
import { E2B, Sandbox } from 'e2b'

const production = new E2B({ apiKey: 'PRODUCTION_API_KEY' })
const staging = new E2B({ apiKey: 'STAGING_API_KEY', domain: 'e2b-staging.dev' })

await production.Sandbox.create()
await staging.Sandbox.create()

// Still uses the E2B_API_KEY environment variable.
await Sandbox.create()
```

```python Python theme={"theme":"css-variables"}
from e2b import E2B, Sandbox

production = E2B(api_key="PRODUCTION_API_KEY")
staging = E2B(api_key="STAGING_API_KEY", domain="e2b-staging.dev")

production.Sandbox.create()
staging.Sandbox.create()

# Still uses the E2B_API_KEY environment variable.
Sandbox.create()
```

```python Python (async) theme={"theme":"css-variables"}
from e2b import E2B, AsyncSandbox

production = E2B(api_key="PRODUCTION_API_KEY")
staging = E2B(api_key="STAGING_API_KEY", domain="e2b-staging.dev")

await production.AsyncSandbox.create()
await staging.AsyncSandbox.create()

# Still uses the E2B_API_KEY environment variable.
await AsyncSandbox.create()
```

## Multiple regions

> [!NOTE]
>
> Regions do not share state. A project and its API key belong to exactly one region, and the sandboxes, templates, and volumes it owns exist only there. Two things to plan for:
>
> * **Build your own templates once per region.** There is no way to copy a template between regions, so run [`Template.build`](https://docs.e2b.dev/template/build) through each region's client. The same template name in every region is fine.
> * **A sandbox ID only resolves in its own region.** Connect to a sandbox, list it, or kill it through the client for the region that created it.

If a single process only ever talks to one region, you do not need a client at all. Set `E2B_API_KEY` and `E2B_DOMAIN` to that region's values and keep using the top-level exports.

E2B's managed cloud runs in several regions. US-West-1 is the default, and [support](https://console.e2b.dev/?support=true) enables the other regions for your account. See [Migrate between regions](https://docs.e2b.dev/faq/migrate-between-regions.md), [EU region](https://docs.e2b.dev/faq/eu-region.md), and [Egress IP ranges](https://docs.e2b.dev/faq/egress-ip-ranges.md) for more on where sandboxes run.

There is no `region` option. Each region is a separate deployment with its own API endpoint, so you select one by pointing a client at that region's `domain`:

| Region | Domain |
| - | - |
| US-West-1 | `e2b.app` (default) |
| US-West-2 | `foxtrot-2.e2b.dev` |
| US-East-1 | `foxtrot-3.e2b.dev` |
| EU-West-1 | `e2b-juliett.dev` |
| AP-Southeast-1 | `e2b-tango.dev` |

When support enables a region, they help you create a [project](https://docs.e2b.dev/projects.md) there. That project has its own API key, so a multiregion setup is one client per region, each with its own key and domain.

```js JavaScript & TypeScript theme={"theme":"css-variables"}
import { E2B } from 'e2b'

// One client per region, each with the API key of that region's project.
const regions = {
  usWest1: new E2B({ apiKey: 'e2b_YOUR_US_WEST_1_KEY' }), // Default domain: e2b.app
  usWest2: new E2B({ apiKey: 'e2b_YOUR_US_WEST_2_KEY', domain: 'foxtrot-2.e2b.dev' }),
  usEast1: new E2B({ apiKey: 'e2b_YOUR_US_EAST_1_KEY', domain: 'foxtrot-3.e2b.dev' }),
  euWest1: new E2B({ apiKey: 'e2b_YOUR_EU_WEST_1_KEY', domain: 'e2b-juliett.dev' }),
  apSoutheast1: new E2B({ apiKey: 'e2b_YOUR_AP_SOUTHEAST_1_KEY', domain: 'e2b-tango.dev' }),
}

// Route each workload to the region it should run in.
const client = regions[user.region] ?? regions.usWest1

const sandbox = await client.Sandbox.create('my-template')
const result = await sandbox.commands.run('echo "Hello from E2B!"')
console.log(result.stdout) // Hello from E2B!
```

```python Python theme={"theme":"css-variables"}
from e2b import E2B

# One client per region, each with the API key of that region's project.
regions = {
    "us_west_1": E2B(api_key="e2b_YOUR_US_WEST_1_KEY"),  # Default domain: e2b.app
    "us_west_2": E2B(api_key="e2b_YOUR_US_WEST_2_KEY", domain="foxtrot-2.e2b.dev"),
    "us_east_1": E2B(api_key="e2b_YOUR_US_EAST_1_KEY", domain="foxtrot-3.e2b.dev"),
    "eu_west_1": E2B(api_key="e2b_YOUR_EU_WEST_1_KEY", domain="e2b-juliett.dev"),
    "ap_southeast_1": E2B(api_key="e2b_YOUR_AP_SOUTHEAST_1_KEY", domain="e2b-tango.dev"),
}

# Route each workload to the region it should run in.
client = regions.get(user_region, regions["us_west_1"])

sandbox = client.Sandbox.create("my-template")
result = sandbox.commands.run('echo "Hello from E2B!"')
print(result.stdout)  # Hello from E2B!
```

```python Python (async) theme={"theme":"css-variables"}
from e2b import E2B

# One client per region, each with the API key of that region's project.
regions = {
    "us_west_1": E2B(api_key="e2b_YOUR_US_WEST_1_KEY"),  # Default domain: e2b.app
    "us_west_2": E2B(api_key="e2b_YOUR_US_WEST_2_KEY", domain="foxtrot-2.e2b.dev"),
    "us_east_1": E2B(api_key="e2b_YOUR_US_EAST_1_KEY", domain="foxtrot-3.e2b.dev"),
    "eu_west_1": E2B(api_key="e2b_YOUR_EU_WEST_1_KEY", domain="e2b-juliett.dev"),
    "ap_southeast_1": E2B(api_key="e2b_YOUR_AP_SOUTHEAST_1_KEY", domain="e2b-tango.dev"),
}

# Route each workload to the region it should run in.
client = regions.get(user_region, regions["us_west_1"])

sandbox = await client.AsyncSandbox.create("my-template")
result = await sandbox.commands.run('echo "Hello from E2B!"')
print(result.stdout)  # Hello from E2B!
```
