跳转到内容
EN

启动任务

先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。

POST/sandbox/v1/sandboxes/{sandboxID}/tasks● 支持

请求参数

  • sandboxIDstring必填

    path: 沙箱 ID。

  • commandstring必填

    The shell command to run. It is handed to the sandbox's daemon in an environment variable, never in argv, so it stays out of the machine's process list; at most 64 KiB of UTF-8.

  • cwdstring可选

    Absolute working directory inside the sandbox. Omit to run where the daemon starts; a relative path is rejected rather than resolved against a home directory you did not choose.

  • maxLifetimeSecsinteger可选

    How long the task may run, in seconds; omit for 7200, the ceiling is 86400 (a day). The pushing credential lives 30 minutes past this, so the daemon can still deliver a task that ran to its limit.

  • filesarray可选

    Up to eight extra files to ship alongside the task's own output, for example a structured events log the task appends to. Each gets its own stream, read with name on sandboxes.tasks.log.

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

      Stream name this file is pushed under, 1 to 32 characters of a-z, 0-9 or a hyphen. output is reserved for the task's own stdout and stderr; read either with sandboxes.tasks.log.

    • pathstring必填

      Absolute path of the file inside the sandbox. It is read as the task runs; a file the task has not created yet is delivered empty rather than refused.

返回

201

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

请求示例

curl
# 先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。
curl https://api.deepraxis.com/sandbox/v1/sandboxes/sbx_123/tasks \
  -H "X-API-Key: $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"command":"echo hello from a task","maxLifetimeSecs":600}'
Python
# 先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。
import requests

api_key = "$PRAXIS_API_KEY"

# Call /sandbox/v1 directly over HTTP.
resp = requests.post(
    "https://api.deepraxis.com/sandbox/v1/sandboxes/sbx_123/tasks",
    headers={"X-API-Key": api_key},
    json={"command": "echo hello from a task", "maxLifetimeSecs": 600},
)
print(resp.status_code, resp.text)
TypeScript
// 先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。
const apiKey = "$PRAXIS_API_KEY";

// Call /sandbox/v1 directly over HTTP.
const resp = await fetch(`https://api.deepraxis.com/sandbox/v1/sandboxes/sbx_123/tasks`, {
  method: "POST",
  headers: { "X-API-Key": apiKey, "Content-Type": "application/json" },
  body: JSON.stringify({ command: "echo hello from a task", maxLifetimeSecs: 600 }),
});
console.log(resp.status, await resp.text());

响应示例 201

{
  "taskId": "tsk_3ijfghmiarjrjkwinlj2",
  "instanceId": "sbi_ef9aee4cfb08f8d13808bf5e",
  "startedAt": 1794264183922
}

响应

HTTP 201

The task started; its log is read with sandboxes.tasks.log

application/json

名称 类型 说明
taskId string Task identifier, opaque and not the sandbox id. It is the address of the pushed log: pass it to sandboxes.tasks.log, and it stays valid after the sandbox is deleted.
instanceId string The sandbox the task runs on, in the same internal spelling the request used.
startedAt integer When the task started, in Unix milliseconds. Compare against log timestamps; it is not the sandbox's creation time.