Complete service authorization, create a template, generate an API Key, and make your first call via the console—launching your first sandbox within minutes.
Sandbox task path
Prerequisites
- You have activated Alibaba Cloud Bailian.
- Your current account has Sandbox operation permissions.
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:
| Field | Value |
|---|---|
| Role name | AliyunServiceRoleForSFMSandbox |
| Role permission policy | AliyunServiceRolePolicyForSFMSandbox |
| Permission description | Allows Bailian to access sandbox compute and network resources to create, run, and release sandbox instances |
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:
| Field | Description |
|---|---|
| Image | Choose one of three: code-interpreter-v1 (code execution), browser (browser operations), all-in-one (combined capabilities) |
| Template name | Required, customizable |
| Resource specification | Required. Spec 1 (1 Core / 2 GB, recommended) or Spec 2 (4 Core / 8 GB) |
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:
{workspace_id}: Follow Sandbox API prerequisites to view the actual workspace ID in the console's top-right menu, or see Get the workspace ID. The API key and template must belong to this workspace.ALIYUN_UID: Sign in to the Alibaba Cloud official website and view Account ID in the top-right profile menu. Replaceyour aliyunUidwith that UID.BAILIAN_API_KEY: Replace it with the actual API key obtained in step 3.template: Replaceyour template codewith thetemplateCoderecorded in step 2. You can select thecode-interpreter-v1image for this example.
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.result.stdout reports the Python version inside the sandbox. Reading the file back prints hello bailian, letting you check command execution and file writing and reading. The Python version depends on the selected template's actual output.