All Products
Search
Document Center

Function Compute:Use FC Agent Sandbox with the CLI

Last Updated:Jul 15, 2026

This guide walks you through using the E2B CLI to view templates, create a sandbox, enter its terminal, and clean up resources.

Prerequisites

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

  • You have created an API key in the Function Compute console.

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

  • You have installed a supported version of the E2B CLI. For version requirements, see Usage Constraints.

1. Install the CLI

On macOS, you can install it with Homebrew:

brew install e2b

You can also install it with npm:

npm i -g @e2b/cli

2. Configure environment variables

Configure the API key, API URL, and domain. 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>.e2b.fc.aliyuncs.com"
export E2B_DOMAIN="<region>.e2b.fc.aliyuncs.com"

Replace <region> with the region where FC Agent Sandbox is deployed. For supported regions and endpoint rules, see Usage Constraints.

E2B_ACCESS_TOKEN is a deprecated legacy E2B authentication variable. New E2B CLI versions should use E2B_API_KEY. If an older CLI still asks for E2B_ACCESS_TOKEN, upgrade the CLI and retry.

You can list sandboxes first to verify the configuration:

e2b sandbox list

3. View templates

e2b template list

The output shows the templates available to your current account. The following example only shows the output format. Template IDs, instance specifications, creation times, and statuses vary by account, region, and template configuration:

Access  Template ID    Template Name         vCPUs  RAM MiB  Created at    Disk size MiB  names                buildStatus
Public  <template-id>  code-interpreter-v1       2     2048  <created-at>          10240  code-interpreter-v1  ready

4. Create and connect to a sandbox

e2b sandbox create code-interpreter-v1

After you enter the sandbox terminal, run:

python3 -c 'print("hello from sandbox")'
exit

5. Connect to an existing sandbox

If a sandbox is already running, you can reconnect to its interactive terminal by sandbox ID:

e2b sandbox connect <sandbox-id>

Exiting the terminal only closes the local terminal session. It does not automatically terminate the sandbox.

6. Execute commands in a sandbox

You can also execute a command in an existing sandbox without entering an interactive terminal:

e2b sandbox exec <sandbox-id> ls

The command output is returned to your local terminal.

7. View sandbox metrics

View CPU and memory metrics for a running sandbox:

e2b sandbox metrics <sandbox-id>

Metrics currently return at 1-minute granularity and are suitable for debugging and observing resource usage trends.

8. View and kill sandboxes

To view the list of sandboxes:

e2b sandbox list

To kill a sandbox you no longer need:

e2b sandbox kill <sandbox-id>

After the task is complete, explicitly kill the sandbox to avoid holding resources longer than necessary.

Next steps