Create sandbox
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
/sandboxesCreate 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
templateIDstringRequiredID of a template that has been created and finished building.
timeoutintegerOptionalInstance lifetime in seconds. Valid range: [300,604800].
allow_internet_accessbooleanOptionalWhether the instance can access the internet.
metadataobjectOptionalCustom metadata. Both keys and values are strings.
envVarsobjectOptionalInstance-level environment variables. Both keys and values are strings.
autoPausebooleanOptionalWhether to pause the instance when timeout expires.
autoResumebooleanOptionalWhether to resume automatically on connect. The object form {"enabled": true} is also accepted.
lifecycleobjectOptionalLifecycle 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).
networkobjectOptionalInstance-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
clientIDstringClient identifier.
sandboxIDstringUnique instance ID, used for subsequent lifecycle and data-plane calls.
bailianSandboxIdstringAlibaba Cloud Model Studio extension identifier. Usually not needed by developers.
templateIDstringTemplate ID.
aliasstringTemplate alias.
envdVersionstringenvd version.
domainstringData-plane access domain.
envdAccessTokenstringenvd access token.
trafficAccessTokenstringTraffic access token.
envdUrlstringenvd access URL.
statestringInstance 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"
}