Create template

Updated at:

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

namestringRequired

Template name.

cpuCountintegerRequired

Number of vCPUs. Must be greater than 0 and, together with the memory size, match a resource specification supported by the platform.

memoryMBintegerRequired

Memory size in MB. Must be greater than 0 and, together with the CPU count, match a resource specification supported by the platform.

fromImagestringOptional

Base 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.

imageNamestringOptional

Image display name.

tagsarray<string>Optional

E2B tags.

aliasstringOptional

E2B template alias.

mntConfigarray<object>Optional

File mount configuration. Sub-fields: originFileName (string, optional, original file name; ignored when mountPath is a directory), originFileId (string, required, ID of a file uploaded with source=sandbox_template and in available status), mountPath (string, required, must start with /home/user/workspace/uploads/; use a full file path. If the path is outside this directory, the API accepts the configuration but the file does not appear in the instance. For upload details, see File upload).

networkConfigobjectOptional

Network 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).

envConfigobjectOptional

Environment variable key-value pairs written into the template runtime. Values are strings.

autoPauseTimeintegerOptional

Auto-pause time on expiry, in seconds. Valid range: [300,604800].

maxRunningTimeoutintegerOptional

Maximum 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.

descriptionstringOptional

Template description.

Response fields

templateIDstring

Template ID.

templateNamestring

Template name.

templateTypestring

Template type, for example CUSTOM.

cpuCountinteger

Number of vCPUs.

memoryMBinteger

Memory size in MB.

publicboolean

Whether the template is public.

regionIdstring

Region.

imageNamestring

Image display name.

buildIDstring

Build ID, used to query the build status.

buildStatusstring

Build status, for example building.

createdAtstring

Creation time in date-time format.

updatedAtstring

Update time in date-time format.

versioninteger

Template 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.

NoteYou can create an instance from the template only after the build status becomes ready. See Get build status.

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": []
}