All Products
Search
Document Center

Agent Sandbox:Use Agent Sandbox Flash Edition with the SDK

Last Updated:Sep 21, 2026

This guide walks you through creating your first Agent Sandbox Flash Edition with the E2B SDK and running a command in it.

Prerequisites

  • You have an Alibaba Cloud account and the required permissions to use Function Compute.

  • You have completed the following configurations: Configure RAM User Permissions, Create a Team, and Create an API Key.

  • You have confirmed that Agent Sandbox Flash Edition is available in the target region and that your local network can access the service endpoint in that region.

  • For the Python example, Python 3.10 or later is installed.

  • For the TypeScript example, Node.js 20.18.1 or later is installed.

For SDK version requirements, supported regions, and endpoint rules, see Usage Constraints.

1. Configure environment variables

Pass the API key, endpoint, and domain through environment variables. Do not hard-code them in your code. For API key creation and management, see Create an API Key.

export E2B_API_KEY="<YOUR-API-KEY>"
export E2B_API_URL="https://api.<region>.sandbox.aliyuncs.com"
export E2B_DOMAIN="<region>.sandbox.aliyuncs.com"

Replace <region> with the region where Agent Sandbox Flash Edition is deployed.

2. Install the E2B SDK

Python

First, confirm that Python is version 3.10 or later, and then create and activate a virtual environment and install the E2B SDK:

python3 --version
python3 -m venv .venv
source .venv/bin/activate
pip install e2b==2.31.0 e2b-code-interpreter==2.8.1

TypeScript

First, confirm that Node.js is version 20.18.1 or later, and then initialize the project and install the E2B SDK and its development dependencies:

node --version
npm init -y
npm install e2b@^2.31.0 @e2b/code-interpreter@^2.6.1
npm install -D tsx typescript @types/node

3. Create and run a sandbox

Run either the Python or TypeScript example.

Python

Create quickstart.py:

import os
from e2b_code_interpreter import Sandbox


def require_env(name: str) -> str:
    value = os.environ.get(name, "").strip()
    if not value:
        raise RuntimeError(f"Missing environment variable: {name}")
    return value


sandbox = None

try:
    sandbox = Sandbox.create(
        template="code-interpreter-v1",
        api_key=require_env("E2B_API_KEY"),
        api_url=require_env("E2B_API_URL"),
        domain=require_env("E2B_DOMAIN"),
    )

    result = sandbox.commands.run("python3 -c \"print('hello from sandbox')\"")
    print(result.stdout.strip())
finally:
    if sandbox is not None:
        sandbox.kill()

Run:

python3 quickstart.py

TypeScript

Create quickstart.ts:

import { Sandbox } from "@e2b/code-interpreter";

async function main() {
  const sandbox = await Sandbox.create("code-interpreter-v1", {
    apiKey: process.env.E2B_API_KEY,
    apiUrl: process.env.E2B_API_URL,
    domain: process.env.E2B_DOMAIN,
    timeoutMs: 300_000,
  });

  try {
    const result = await sandbox.commands.run("python3 -c \"print('hello from sandbox')\"");
    console.log(result.stdout.trim());
  } finally {
    await sandbox.kill();
  }
}

main();

Run:

npx tsx quickstart.ts

If you see hello from sandbox, the SDK, API key, endpoint, domain, and built-in template are all working correctly.

Next steps