> ## Documentation Index
> Fetch the complete documentation index at: https://e2b.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://e2b.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://e2b.manicule.dev/api/mcp.
> Every agent surface: https://e2b.manicule.dev/.well-known/llms-manifest.json

# Install custom packages (/docs/quickstart/install-custom-packages)

<!-- agent-signals: reading_time_min: 3 · est_tokens: 1319 · updated: 2026-07-30 -->
Related: [Connect LLMs to E2B](/docs/quickstart/connect-llms.md), [Upload & downloads files](/docs/quickstart/upload-download-files.md)

There are two ways to install custom packages in the E2B Sandbox.

1. [Create custom sandbox with preinstalled packages](#create-a-custom-sandbox).
2. [Install packages during the sandbox runtime](#install-packages-during-the-sandbox-runtime).

***

## Create a custom sandbox

Use this option if you know beforehand what packages you need in the sandbox.

<Note>Sandbox templates allow you to define custom sandboxes with preinstalled packages and configurations.</Note>

### 1. Install the E2B SDK

<CodeGroup>
```bash title="JavaScript & TypeScript"
npm install e2b dotenv
```

```bash title="Python"
pip install e2b python-dotenv
```
</CodeGroup>

Create a `.env` file with your API key:

```bash
E2B_API_KEY=e2b_***
```

### 2. Create a template file

Define your custom template with the packages you need.

<CodeGroup>
```typescript title="JavaScript & TypeScript"
// template.ts
import { Template } from 'e2b';

export const template = Template()
  .fromTemplate("code-interpreter-v1")
  .pipInstall(['cowsay'])  // Install Python packages
  .npmInstall(['cowsay']);  // Install Node.js packages
```

```python title="Python"
# template.py
from e2b import Template

template = (
    Template()
    .from_template("code-interpreter-v1")
    .pip_install(['cowsay'])  # Install Python packages
    .npm_install(['cowsay'])  # Install Node.js packages
)
```
</CodeGroup>

### 3. Create a build script

<CodeGroup>
```typescript title="JavaScript & TypeScript"
// build.prod.ts
import "dotenv/config";
import { Template, defaultBuildLogger } from 'e2b';
import { template } from './template';

async function main() {
  await Template.build(template, 'custom-packages', {
    cpuCount: 2,
    memoryMB: 2048,
    onBuildLogs: defaultBuildLogger(),
  });
}

main().catch(console.error);
```

```python title="Python"
# build.prod.py
from dotenv import load_dotenv
from e2b import Template, default_build_logger
from template import template

load_dotenv()

if __name__ == '__main__':
    Template.build(
        template,
        'custom-packages',
        cpu_count=2,
        memory_mb=2048,
        on_build_logs=default_build_logger(),
    )
```
</CodeGroup>

### 4. Build the template

Run the build script to create your custom template:

<CodeGroup>
```bash title="JavaScript & TypeScript"
npx tsx build.prod.ts
```

```bash title="Python"
python build.prod.py
```
</CodeGroup>

This will build your template and you'll see build logs in the console.

### 5. Use your custom sandbox

Now you can create sandboxes from your custom template:

<CodeGroup>
```js title="JavaScript & TypeScript"
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create("custom-packages")

// Your packages are already installed and ready to use
```

```python title="Python"
from e2b import Sandbox

sbx = Sandbox.create("custom-packages")

# Your packages are already installed and ready to use
```
</CodeGroup>

***

## Install packages during the sandbox runtime

Use this option if don't know beforehand what packages you need in the sandbox. You can install packages with the package manager of your choice.

<Note>The packages installed during the runtime are available only in the running sandbox instance.
When you start a new sandbox instance, the packages are not be available.</Note>

### 1. Install Python packages with PIP

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

const sbx = await Sandbox.create()
sbx.commands.run('pip install cowsay') // This will install the cowsay package
sbx.runCode(`
  import cowsay
  cowsay.cow("Hello, world!")
`)
```

```python title="Python"
from e2b_code_interpreter import Sandbox

sbx = Sandbox.create()
sbx.commands.run("pip install cowsay") # This will install the cowsay package
sbx.run_code("""
  import cowsay
  cowsay.cow("Hello, world!")
""")
```
</CodeGroup>

### 2. Install Node.js packages with NPM

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

const sbx = await Sandbox.create()
sbx.commands.run('npm install cowsay') // This will install the cowsay package
sbx.runCode(`
  const cowsay = require('cowsay')
  console.log(cowsay.say({ text: 'Hello, world!' }))
`, { language: 'javascript' })
```

```python title="Python"
from e2b_code_interpreter import Sandbox

sbx = Sandbox.create()
sbx.commands.run("npm install cowsay") # This will install the cowsay package
sbx.run_code("""
  import { say } from 'cowsay'
  console.log(say('Hello, world!'))
""", language="javascript")
```
</CodeGroup>

### 3. Install packages with package manager of your choice

Since E2B Sandboxes are Debian based machines, you can use any package manager supported by Debian.
You just need to make sure that the package manager is already installed in the sandbox.

For example, to install `curl` and `git`, you can use the following commands:

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

const sbx = await Sandbox.create()
await sbx.commands.run('apt-get update && apt-get install -y curl git')
```

```python title="Python"
from e2b_code_interpreter import Sandbox

sbx = Sandbox.create()
sbx.commands.run("apt-get update && apt-get install -y curl git")
```
</CodeGroup>
