All Products
Search
Document Center

Function Compute:Lifecycle

Last Updated:Jul 13, 2026

A Sandbox is the core runtime object in FC Agent Sandbox. After you create a Sandbox, you can run commands, read and write files, execute code, or start temporary services inside it. When the task is complete, explicitly terminate the Sandbox.

Create a Sandbox

Create a code-interpreter-v1 Sandbox:

import os

from e2b_code_interpreter import Sandbox

sandbox = Sandbox.create(
    template="code-interpreter-v1",
    api_key=os.environ["E2B_API_KEY"],
    api_url=os.environ["E2B_API_URL"],
    domain=os.environ["E2B_DOMAIN"],
)

You can also use the TypeScript SDK:

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

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,
});

Sandbox.create() supports parameters such as templates, timeouts, environment variables, and metadata. For details on environment variables and metadata, see Environment Variables and Metadata.

Connect to a Sandbox

Use Sandbox.connect(sandboxId) to connect to an existing Sandbox. If the target Sandbox is paused, it is automatically resumed when you connect.

Query Sandboxes

You can query Sandboxes under the current account or retrieve information about a specific Sandbox:

  • Sandbox.list(): Lists Sandboxes.

  • sandbox.getInfo(): Retrieves information about the current Sandbox.

  • sandbox.isRunning(): Checks whether the Sandbox is running.

Kill a Sandbox

After the task is complete, explicitly terminate the Sandbox:

sandbox.kill()

Set the Timeout

Use sandbox.setTimeout(ms) to adjust the Sandbox timeout. For details, see Timeouts.

Further reading