Use the CLI with Agent Sandbox Flash Edition
Use 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 permissions required to perform Function Compute operations.
You have completed the following configurations: Configure RAM User Permissions, Create a Team, and Create an API Key.
You have confirmed that the target region supports Agent Sandbox Flash Edition and that your local network can access the Agent Sandbox Flash Edition service in that region.
You have installed a version of the E2B CLI that meets the version requirements. For details, see Usage constraints.
1. Install the CLI
On macOS, use Homebrew:
brew install e2bAlternatively, use npm:
npm i -g @e2b/cli@2.20.0After installation, check the version:
e2b --version2. Configure environment variables
Configure the API key, API URL, and domain. For information about how to create and manage an API key, 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"In these commands, <region> is the region where the Agent Sandbox Flash Edition service is deployed. For supported regions and endpoint rules, see Usage constraints.
E2B_ACCESS_TOKEN is a deprecated legacy E2B authentication variable. New versions of the E2B CLI should use E2B_API_KEY. If an older CLI version still requires E2B_ACCESS_TOKEN, upgrade the CLI and try again.
List sandboxes first to verify that the configuration takes effect:
e2b sandbox list3. View templates
e2b template listThe output lists the templates available to your current account. The following example shows only the output format. Template IDs, 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> 15360 code-interpreter-v1 ready4. Create and connect to a sandbox
e2b sandbox create code-interpreter-v1After you enter the sandbox terminal, run:
python3 -c 'print("hello from sandbox")'
exit5. Connect to an existing sandbox
If a sandbox is already running, 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. Run commands in a sandbox
Alternatively, run a command directly in an existing sandbox without entering the interactive terminal:
e2b sandbox exec <sandbox-id> lsThe command output is returned to your local terminal.
7. View sandbox metrics
View the CPU and memory metrics of a running sandbox:
e2b sandbox metrics <sandbox-id>Metrics are currently returned at 1-minute granularity, which is suitable for debugging and observing resource usage trends.
8. View and terminate sandboxes
View the list of sandboxes:
e2b sandbox listTerminate a sandbox that you no longer use:
e2b sandbox kill <sandbox-id>After the task is complete, explicitly terminate the sandbox to avoid continued resource consumption.
Next steps
To create and manage sandboxes in your application by using the SDK, see Use Agent Sandbox Flash Edition with the SDK.