Skip to main content

Create template

Create a sandbox template. On success, the response returns templateID and buildID. Wait until the build status becomes ready before you create an instance.

Prerequisites

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

Endpoint

POST /v3/templates Create a sandbox template. The route POST /templates is also supported. On success, the response returns templateID and buildID. Wait until the build status becomes ready before you create an instance. cpuCount and memoryMB must be passed together and must match a resource specification supported by the platform. Invalid JSON returns an explicit format error.

Request body

FieldRequiredTypeDescription
nameYesstringTemplate name.
cpuCountYesintegerNumber of vCPUs. Must be greater than 0 and, together with the memory size, match a resource specification supported by the platform.
memoryMBYesintegerMemory size in MB. Must be greater than 0 and, together with the CPU count, match a resource specification supported by the platform.
fromImageNostringBase image, specified as a full image address. Official images are under fc-e2b-registry.cn-beijing.cr.aliyuncs.com/runtime/: code-interpreter-v1, browser, and all-in-one. The platform default image (code interpreter) is used when omitted.
imageNameNostringImage display name.
tagsNoarray<string>E2B tags.
aliasNostringE2B template alias.
mntConfigNoarray<object>File mount configuration. Sub-fields: originFileName (string, optional, original file name), originFileId (string, required, ID of a file that exists in the current workspace), mountPath (string, required, mount path inside the instance).
networkConfigNoobjectNetwork rules. Sub-fields: allowOut (array<string>, egress allowlist, supports IPv4, IPv6, CIDR, and domain names), denyOut (array<string>, egress denylist, supports IPv4, IPv6, and CIDR only — domain names are not supported).
envConfigNoobjectEnvironment variable key-value pairs written into the template runtime. Values are strings.
autoPauseTimeNointegerAuto-pause time on expiry, in seconds. Valid range: [300,604800].
maxRunningTimeoutNointegerMaximum running time in seconds. Valid range: [300,604800]. The instance is released automatically on expiry. If only autoPauseTime is set, the instance is paused on expiry; if both are set, maxRunningTimeout takes effect; if neither is set, the maximum running time defaults to 604800 seconds.
descriptionNostringTemplate description.

Request example

curl -X POST "$BASE_URL/v3/templates" \
  -H "Authorization: Bearer $BAILIAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-template",
    "cpuCount": 1,
    "memoryMB": 2048,
    "envConfig": {"STAGE": "dev"},
    "networkConfig": {
      "allowOut": ["example.com"],
      "denyOut": ["10.0.0.0/8"]
    },
    "autoPauseTime": 1800,
    "maxRunningTimeout": 3600,
    "description": "my first sandbox template"
  }'
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 202 on success, which means the template has been submitted for building.
{
  "templateID": "your-template-id",
  "templateName": "my-template",
  "templateType": "CUSTOM",
  "cpuCount": 1,
  "memoryMB": 2048,
  "public": false,
  "regionId": "cn-beijing",
  "imageName": "your-image-name",
  "buildID": "your-build-id",
  "buildStatus": "building",
  "createdAt": "2026-01-01T00:00:00Z",
  "updatedAt": "2026-01-01T00:00:00Z",
  "version": 1,
  "tags": [],
  "aliases": []
}

Response fields

FieldTypeDescription
templateIDstringTemplate ID.
templateNamestringTemplate name.
templateTypestringTemplate type, for example CUSTOM.
cpuCountintegerNumber of vCPUs.
memoryMBintegerMemory size in MB.
publicbooleanWhether the template is public.
regionIdstringRegion.
imageNamestringImage display name.
buildIDstringBuild ID, used to query the build status.
buildStatusstringBuild status, for example building.
createdAtstringCreation time in date-time format.
updatedAtstringUpdate time in date-time format.
versionintegerTemplate version number.
tagsarray<string>Tags. Not treated as a persisted field until it is returned reliably by subsequent list and get template calls.
aliasesarray<string>Alias list. Not treated as a persisted field until it is returned reliably by subsequent list and get template calls.
You can create an instance from the template only after the build status becomes ready. See Get build status.
Managed Agent API
Flow Agent API
RAG API
Long-term Memory
ParseX API
Security API
Framework Integration