Skip to main content
Getting Started

Quick Start

Complete service authorization, create a template, generate an API Key, and make your first call via the console—launching your first sandbox within minutes.

Prerequisites

Step 1: Complete Service Authorization

When using Sandbox for the first time, complete the Service Linked Role (SLR) authorization so that Bailian can create and manage the sandbox runtime environment. Navigate to Bailian Console > Sandbox. The "Alibaba Cloud Service Authorization" dialog appears the first time you create a template:
FieldValue
Role nameAliyunServiceRoleForSFMSandbox
Role permission policyAliyunServiceRolePolicyForSFMSandbox
Permission descriptionAllows Bailian to access sandbox compute and network resources to create, run, and release sandbox instances
Select the Data Access Authorization Agreement, then click Confirm Authorization to complete this one-time authorization.

Step 2: Create a Template

A template defines the sandbox runtime environment. Go to Sandbox > My Templates, click Create Template, and configure the following fields:
FieldDescription
ImageChoose one of three: code-interpreter-v1 (code execution), browser (browser operations), all-in-one (combined capabilities)
Template nameRequired, customizable
Resource specificationRequired. Spec 1 (1 Core / 2 GB, recommended) or Spec 2 (4 Core / 8 GB)
For file mounts, network allow/deny lists, environment variables, or lifecycle control, expand Advanced Configuration. Click Create when done. After creation, the template appears in the list; record its templateCode for later calls.
In lifecycle control, choose either idle timeout or maximum lifetime, up to 7 days.

Step 3: Get an API Key

Calls to the sandbox are authenticated with a Bailian API Key. Click API-KEY at the bottom left of the Sandbox page to create or copy an API Key (format sk-...).

Step 4: Make Your First Call

Sandbox is compatible with the E2B SDK. After installing the SDK, create an instance and execute code using the Bailian sandbox endpoint and API Key. Install the SDK:
pip install "e2b==2.31.0"
# For Code Interpreter capabilities such as run_code
pip install "e2b-code-interpreter==2.8.1"
Create an instance and execute:
from e2b import Sandbox

ALIYUN_UID = "your aliyunUid"       # Alibaba Cloud UID
BAILIAN_API_KEY = "sk-..."            # Bailian API Key

sbx = Sandbox.create(
    api_url="https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sandbox",
    api_key=f"e2b_{ALIYUN_UID}",      # Placeholder; only needs to match the E2B SDK format
    headers={"Authorization": f"Bearer {BAILIAN_API_KEY}"},  # Bailian API Key for authentication
    template="your template code",
)

# Run a command
result = sbx.commands.run("python --version")
print(result.stdout)

# Write and read a file
sbx.files.write("/home/user/workspace/hello.md", "hello bailian")
print(sbx.files.read("/home/user/workspace/hello.md"))
api_key is a required parameter of the E2B SDK. It only needs to match the format e2b_ followed by hexadecimal characters; e2b_${ALIYUN_UID} is recommended. Bailian's real authentication uses Authorization: Bearer <Bailian API Key> and does not use api_key.

Next Steps