Manage the sandbox instance lifecycle and perform data-plane operations through the E2B SDK. Using the Bailian sandbox endpoint and API Key, create instances, run commands, execute code, and read/write files.
Sandbox is compatible with the E2B SDK. After installing the official E2B SDK, point the endpoint to the Bailian sandbox and authenticate with a Bailian API Key to create instances, run commands, execute code, and read/write files.
The examples in this document are verified with the following versions:
Create a cloud sandbox from a template code using a Bailian API Key. On success, you get a
After connecting to the sandbox, run commands, execute code, and read/write files as if they were local.
Pause the sandbox when idle; reconnecting resumes it from the paused point. Release resources when no longer needed.
Data-plane operations are best performed through the SDK, which uses the domain and token returned by the connect call to reach the sandbox runtime directly.
Recommended Versions
The examples in this document are verified with the following versions:
Authentication and Endpoint
| Parameter | Description |
|---|---|
api_url | Bailian sandbox endpoint, in the form https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sandbox |
Authorization | Bearer <Bailian API Key>, used for real authentication |
api_key | Required parameter of the E2B SDK, only to match the SDK format; e2b_${ALIYUN_UID} is recommended |
template | The template code, i.e., the templateCode created in the console |
api_key only needs to match the format e2b_ followed by hexadecimal characters. An Alibaba Cloud UID is numeric and naturally passes validation (for example, e2b_your aliyunUid). Bailian does not use api_key for business authentication.Step 1: Create an Instance
Create a cloud sandbox from a template code using a Bailian API Key. On success, you get a sandbox_id used for all subsequent access and management.
Step 2: Access the Instance
After connecting to the sandbox, run commands, execute code, and read/write files as if they were local.
Step 3: Manage the Instance Lifecycle
Pause the sandbox when idle; reconnecting resumes it from the paused point. Release resources when no longer needed.
Supported Capabilities
Instance Lifecycle
| Capability | SDK Method |
|---|---|
| Create instance | Sandbox.create(template=...) |
| Get instance info | sbx.get_info() |
| Connect to instance | Sandbox.connect(sandbox_id=...) |
| Pause instance | sbx.pause() |
| Release instance | sbx.kill() |
Data-Plane Operations
Data-plane operations are best performed through the SDK, which uses the domain and token returned by the connect call to reach the sandbox runtime directly.
| Capability | SDK Method | Underlying Data-Plane Request |
|---|---|---|
| Run a command | sbx.commands.run(...) | POST /process.Process/Start |
| Make a directory | sbx.files.make_dir(path) | SDK filesystem RPC |
| Write a file | sbx.files.write(path, content) | POST /files?path=... |
| Read a file | sbx.files.read(path) | GET /files?path=... |
| Run code | sbx.run_code(...) | POST :49999/execute |
Template management has no stable SDK object methods; call the control-plane API over raw HTTP instead—see Sandbox API - Template Management. Instance lifecycle and data-plane operations use the SDK methods above.