Skip to main content

Create an environment

Create a runtime environment. The request body defines the sandbox type, preinstalled dependencies, and network policy; the response returns the full Environment object.

Prerequisites

Endpoint and authentication are configured. See Overview and authentication.

Endpoint

POST /environments

Request body

name string (必选)Unique identifier within the workspacedescription string (可选)Description of the environment's purposescope string (可选)Scope of the environment. organization: visible to and reusable by all members of the workspace. Defaults to organizationconfig.type string (可选)Sandbox type. cloud = cloud container. Immutable after creation. Defaults to cloud when config is omittedconfig.packages object (可选)Preinstalled dependencies grouped by package manager. Keys are apt | pip | npm; values are arrays of package names. Installation may require warm-up time; until it completes, the environment cannot be bound to sessionsconfig.networking object (可选)Network policy object, shaped as {"type": "unrestricted"}. Currently only unrestricted outbound access is supportedmetadata object (可选)Custom business key-value pairs; do not affect runtime behavior

Request example

curl -X POST "$AGENTSTUDIO_URL/environments" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "data-sandbox",
    "description": "Data analysis sandbox",
    "scope": "organization",
    "metadata": {"team": "infra"},
    "config": {
      "type": "cloud",
      "packages": {
        "apt": ["ffmpeg"],
        "pip": ["pandas", "numpy", "matplotlib"]
      },
      "networking": {"type": "unrestricted"}
    }
  }'

Response fields

id stringEnvironment ID, format env_ + base64-encoded string, for example env_N2M2OTc4NTY4ZjRkNDEwZTtype stringFixed value environmentname / description / scope / config / metadata string / objectSame as the request body; config contains the full runtime configuration (sandbox type, preinstalled dependencies, network policy)archived_at string | nullArchive time; null when not archivedcreated_at / updated_at stringCreation / last update time, ISO 8601requestId stringUnique identifier for this request

Response example

{
  "id": "env_xxx",
  "type": "environment",
  "name": "data-sandbox",
  "description": "Data analysis sandbox",
  "scope": "organization",
  "config": {
    "type": "cloud",
    "packages": {"apt": ["ffmpeg"], "pip": ["pandas", "numpy", "matplotlib"]},
    "networking": {"type": "unrestricted"}
  },
  "metadata": {"team": "infra"},
  "archived_at": null,
  "created_at": "2026-06-16T12:45:34+08:00",
  "updated_at": "2026-06-16T12:45:34+08:00",
  "requestId": "xxx"
}
The response is an Environment object. Fields: