Create environment template
Create a reusable environment template that stores container, dependency, network, initial file, and skill configuration.
Endpoint
Returns 201 and the complete environment template. The request body can be empty; in that case the template is created with default configuration.
/agents/environments/templatesRequest body
namestring / nullOptionalTemplate name
packagesobjectOptionalPackages grouped by npm, python, and system; all three groups default to empty arrays
envobject<string,string>OptionalEnvironment variables; names must match [A-Za-z_][A-Za-z0-9_]*, cannot be PATH, and cannot start with a server-reserved prefix; values cannot contain NUL
setup_commandsarrayOptionalSetup commands executed in order. Each item requires command and accepts an optional cwd; cwd defaults to /workspace
networkobjectOptionalNetwork policy, defaults to enabled; blocked_domains is not accepted
desktopobjectOptionalDesktop settings; only enabled=false is accepted, and enabled=true returns 400
capability_directoriesarray<string>OptionalCapability discovery directories, defaults to []
skillsarrayOptionalSkill configuration, fixed as skill_reference
pluginsarrayOptionalPlugin configuration; only an empty array is supported, and non-empty arrays return 400
filesarrayOptionalInitial file configuration, fixed as file_id
Properties
packages
pythonarray<string>OptionalPython packages
systemarray<string>OptionalSystem packages
npmarray<string>Optionalnpm packages
setup_commands
commandstringOptionalSetup command
cwdstringOptionalWorking directory, defaults to /workspace
network
accessstringOptionalNetwork access mode, enabled, disabled, or restricted
allowed_domainsarray<string>OptionalAllowed domains when access=restricted
desktop
enabledbooleanOptionalWhether the desktop is enabled
Template responses do not return env or setup_commands. files is always file_id, and skills is always skill_reference.
Request example
curl -sS -X POST "$BASE_URL/agents/environments/templates" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "OpenAI-Beta: agents=v1" \
-H "Content-Type: application/json" \
-d '{
"name": "example-template",
"network": {"access": "disabled"},
"capability_directories": ["/workspace/skills"]
}'
template = client.beta.agents.environments.templates.create(
name="example-template",
network={"access": "disabled"},
capability_directories=["/workspace/skills"],
)
print(template.id, template.name)
Response fields
idstringEnvironment template ID
objectstringEnvironment template object type, fixed as agent.environment.template
namestring / nullTemplate name
created_atintegerCreation time in Unix seconds
updated_atintegerLast update time in Unix seconds
packagesobjectPackages with python, system, and npm
networkobjectNetwork policy with access and allowed_domains
desktopobjectDesktop settings with enabled
capability_directoriesarray<string>Capability discovery directories
skillsarraySkill configuration with type, skill_id, and version
pluginsarraySafe plugin metadata. Contains type, name, and description; currently an empty array
filesarrayInitial file configuration; each item contains type, path, and file_id
Response example
{
"id": "envtmpl_xxx",
"name": "example-template",
"object": "agent.environment.template",
"created_at": 1794319007,
"updated_at": 1794319007,
"packages": {"python": [], "system": [], "npm": []},
"network": {"access": "disabled", "allowed_domains": []},
"desktop": {"enabled": false},
"capability_directories": ["/workspace/skills"],
"skills": [],
"plugins": [],
"files": []
}
Error codes
| HTTP status | Error type / code | Solution |
|---|---|---|
400 | invalid_request_error / invalid_request_error | Fix the request body as described for each field |
400 | invalid_request_error / invalid_request_error | desktop.enabled=true, non-empty plugins, and network.blocked_domains are rejected; adjust the field accordingly |
401 | authentication_error / invalid_api_key | Send a valid Authorization: Bearer $DASHSCOPE_API_KEY header |
500 | server_error / server_error | Retry later. If it keeps failing, submit a ticket with x-request-id |