Create an environment

Updated at:

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

FieldRequiredTypeDescription
nameYesstringUnique identifier within the workspace
descriptionNostringDescription of the environment's purpose
scopeNostringScope of the environment. organization: visible to and reusable by all members of the workspace. Defaults to organization
config.typeNostringSandbox type. cloud = cloud container. Immutable after creation. Defaults to cloud when config is omitted
config.packagesNoobjectPreinstalled dependencies grouped by package manager. Keys are apt | pip | npm; values are arrays of package names
config.networkingNoobjectNetwork policy object, shaped as {"type": "unrestricted"}. Currently only unrestricted outbound access is supported
metadataNoobjectCustom 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"}
    }
  }'
env = client.environments.create(
    name="data-sandbox",
    config={
        "type": "cloud",
        "networking": {"type": "unrestricted"},
        "packages": {
            "apt": ["ffmpeg"],
            "pip": ["pandas", "numpy", "matplotlib"],
        },
    },
    description="Data analysis sandbox",
    scope="organization",
    metadata={"team": "infra"},
)
Environment env = client.environments().create(EnvironmentCreateParam.builder()
    .name("data-sandbox")
    .description("Data analysis sandbox")
    .build());

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:

Response fields

FieldTypeDescription
idstringEnvironment ID, format env_ + base64-encoded string, for example env_N2M2OTc4NTY4ZjRkNDEwZT
typestringFixed value environment
name / description / scope / config / metadatastring / objectSame as the request body; config contains the full runtime configuration (sandbox type, preinstalled dependencies, network policy)
archived_atstring | nullArchive time; null when not archived
created_at / updated_atstringCreation / last update time, ISO 8601
requestIdstringUnique identifier for this request