沙箱

创建沙箱

从模板创建一个沙箱,返回沙箱 ID 与数据面访问凭证。

POST /sandbox/v1/sandboxes● 支持

E2B 官方文档 ↗

请求体

  • templateIDstring必填

    Identifier of the required template

  • timeoutinteger可选
    默认 300

    Lifetime of the new sandbox in seconds. Defaults to 300 seconds when omitted.

  • autoPauseboolean可选
    默认 false

    Automatically pauses the sandbox after the timeout

  • metadataany可选

    Your own string key/value pairs stored with the sandbox; usable as a filter in listSandboxes.

  • envVarsany可选

    Environment variables as name to value string pairs.

  • allow_internet_accessboolean可选

    Allow sandbox to access the internet. When set to false, it behaves the same as specifying denyOut to 0.0.0.0/0 in the network config.

  • autoPauseMemoryboolean可选
    默认 true

    Controls the snapshot kind taken when the sandbox auto-pauses on timeout (only relevant when autoPause is true). When false, the auto-pause drops the in-memory state and persists only the filesystem (a filesystem-only snapshot); resuming it cold-boots (reboots) the sandbox from disk. Such a snapshot cannot be auto-resumed by traffic and must be resumed explicitly, so it cannot be combined with autoResume. Defaults to true (full memory snapshot).

  • autoResumeobject可选

    Auto-resume configuration for paused sandboxes.

    ▸ 展开子字段(1)
    • enabledboolean必填
      默认 false

      Auto-resume enabled flag for paused sandboxes. Default false.

  • networkobject可选

    Network policy of the sandbox: public access, egress allow and deny lists and proxy.

    ▸ 展开子字段(7)
    • allowPublicTrafficboolean可选
      默认 true

      Specify if the sandbox URLs should be accessible only with authentication.

    • allowOutarray可选

      List of allowed destinations for egress traffic. Each entry can be a CIDR block (e.g. "8.8.8.8/32"), a bare IP address (e.g. "8.8.8.8"), or a domain name (e.g. "example.com", "*.example.com"). Allowed entries always take precedence over denied entries.

    • denyOutarray可选

      List of denied CIDR blocks or IP addresses for egress traffic. Domain names are not supported for deny rules.

    • egressProxyobject可选

      SOCKS5 proxy for sandbox egress. Outbound TCP is tunneled through the proxy after allow/deny filtering; the sandbox is unaware. Domain-matched flows use remote DNS (ATYP=domain).

    • maskRequestHoststring可选

      Specify host mask which will be used for all sandbox requests

    • httpsPortsarray可选

      Sandbox ports that serve HTTPS rather than plaintext HTTP. Affects how the proxy reaches the service inside the sandbox; the public URL is HTTPS either way. Certificates are not verified, so self-signed ones work. The envd port (49983) cannot be listed.

    • rulesobject可选

      Per-domain transform rules applied to matching outbound HTTPS requests. Keys may be exact DNS names (for example, "api.example.com") or a leading wildcard (for example, "*.example.com"), and are normalized to lowercase on write. Wildcards match subdomains at any depth but not the apex domain; a bare "*" is invalid. Exact rules take precedence, followed by the longest matching wildcard suffix, and matching rule sets are not merged. Broad wildcards such as "*.com" are allowed and may expose transformed credentials to every matching destination the sandbox contacts. Rules do not grant network access; configure allowOut separately to permit the destination.

  • mcpobject可选

    MCP configuration for the sandbox

  • ▸ 更多参数(2)
    • iamobject可选

      Sandbox workload identity configuration. A non-empty, valid tokens map enables workload identity for the sandbox.

      ▸ 展开子字段(1)
      • tokensobject可选

        Named workload-token definitions, keyed by a caller-chosen token name.

    • volumeMountsarray可选

      Volumes to mount into the sandbox, each with the volume name and the path inside the sandbox.

      ▸ 展开子字段(2)
      • namestring必填

        Name of the volume

      • pathstring必填

        Path of the volume

返回

201

平台暂未提供 E2B 默认的 base 模板:不带模板参数的 Sandbox.create() 会返回 404,请显式指定模板(可用模板见「列出模板」)。

错误按 E2B 格式返回,参见 错误码

响应

HTTP 201

The sandbox was created successfully

application/json

名称类型说明
templateIDstringIdentifier of the template from which is the sandbox created
sandboxIDstringIdentifier of the sandbox
aliasstringAlias of the template
clientIDstringIdentifier of the client
envdVersionstringVersion of the envd running in the sandbox
envdAccessTokenstringAccess token used for envd communication
trafficAccessTokenstringToken required for accessing sandbox via proxy.
domainstringBase domain where the sandbox traffic is accessible