Create sandbox

Updated at:

Create a sandbox instance from a template that has finished building. On success, the response returns the instance sandboxID for subsequent access and management. Compatible with the E2B create-sandbox protocol. Returns 409 if the template has not finished building.

Prerequisites

Configure the endpoint and authentication first. See API overview and authentication.

Endpoint

POST/sandboxes

Create a sandbox instance from a template that has finished building. Compatible with the E2B create-sandbox protocol. Returns 409 if the template has not finished building.

Request body

templateIDstringRequired

ID of a template that has been created and finished building.

timeoutintegerOptional

Instance lifetime in seconds. Valid range: [300,604800].

allow_internet_accessbooleanOptional

Whether the instance can access the internet.

metadataobjectOptional

Custom metadata. Both keys and values are strings.

envVarsobjectOptional

Instance-level environment variables. Both keys and values are strings.

autoPausebooleanOptional

Whether to pause the instance when timeout expires.

autoResumebooleanOptional

Whether to resume automatically on connect. The object form {"enabled": true} is also accepted.

lifecycleobjectOptional

Lifecycle configuration. Sub-fields: on_timeout (string, behavior on expiry; pause pauses the instance; an object carrying action is also accepted), auto_resume (boolean, whether connecting to a paused instance resumes it automatically).

networkobjectOptional

Instance-level network configuration. Sub-fields: allowOut (array<string>, egress allowlist), denyOut (array<string>, egress denylist), maskRequestHost (string, optional request Host override), rules (object, extended network rules). The aliases allow_public_traffic, allow_out, deny_out, and mask_request_host are also accepted.

Response fields

clientIDstring

Client identifier.

sandboxIDstring

Unique instance ID, used for subsequent lifecycle and data-plane calls.

bailianSandboxIdstring

Alibaba Cloud Model Studio extension identifier. Usually not needed by developers.

templateIDstring

Template ID.

aliasstring

Template alias.

envdVersionstring

envd version.

domainstring

Data-plane access domain.

envdAccessTokenstring

envd access token.

trafficAccessTokenstring

Traffic access token.

envdUrlstring

envd access URL.

statestring

Instance state, for example running.

Request example

curl -X POST "$BASE_URL/sandboxes" \
  -H "Authorization: Bearer $BAILIAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "templateID": "your-template-id",
    "timeout": 3600,
    "allow_internet_access": true,
    "metadata": {"team": "data"},
    "envVars": {"STAGE": "dev"},
    "autoPause": true,
    "lifecycle": {"on_timeout": "pause", "auto_resume": true}
  }'

BASE_URL is https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sandbox, and BAILIAN_API_KEY is your Alibaba Cloud Model Studio API key.

Response example

Returns 201 on success.

{
  "clientID": "your-client-id",
  "sandboxID": "sbx-xxx",
  "bailianSandboxId": "your-bailian-sandbox-id",
  "templateID": "your-template-id",
  "alias": "your-template-alias",
  "envdVersion": "your-envd-version",
  "domain": "your-sandbox-domain",
  "envdAccessToken": "your-envd-access-token",
  "trafficAccessToken": "your-traffic-access-token",
  "envdUrl": "your-envd-url",
  "state": "running"
}