跳转到内容
EN

沙箱 API

(待译)

Sandbox runs isolated environments for commands, files and HTTP services through /sandbox/v1, with an SDK-compatible face at /e2b. Concepts and behavior follow E2B (templates, builds, tags, sandboxes, files, commands and pause/resume), so E2B experience applies. Unlike E2B, the own face uses one v1 prefix; template builds reject local COPY/ADD, accept only official names in fromTemplate, and reject plaintext registry credentials. The own face accepts a Dockerfile and vault credential references for private images. network.httpsPorts is rejected; omit it. Sandbox also serves android phones: create one with templateID “android”. A phone is a real mobile device with a screen, not a terminal: it has no terminal, process or file API, so file reads and writes answer 501, and its commands do not take the E2B path. Drive the screen with praxis.sandbox.sandboxes.act and run shell commands with praxis.sandbox.sandboxes.commands.run. Start with praxis.sandbox.templates.build to build a template and wait for readiness.

基础地址

https://api.deepraxis.com/sandbox/v1

接入

curl
curl https://api.deepraxis.com/sandbox/v1/sandboxes \
  -H "X-API-Key: $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"templateID":"node22","timeout":300,"ephemeral":false}'
Python
import os

import requests

api_key = os.environ["PRAXIS_API_KEY"]

# Call /sandbox/v1 directly over HTTP.
resp = requests.post(
    "https://api.deepraxis.com/sandbox/v1/sandboxes",
    headers={"X-API-Key": api_key},
    json={"templateID": "node22", "timeout": 300, "ephemeral": False},
)
print(resp.status_code, resp.text)
TypeScript


const apiKey = process.env.PRAXIS_API_KEY;

// Call /sandbox/v1 directly over HTTP.
const resp = await fetch(`https://api.deepraxis.com/sandbox/v1/sandboxes`, {
  method: "POST",
  headers: { "X-API-Key": apiKey, "Content-Type": "application/json" },
  body: JSON.stringify({ templateID: "node22", timeout: 300, ephemeral: false }),
});
console.log(resp.status, await resp.text());

HTTP 与 SDK 接入

用 HTTP 直接调用 /sandbox/v1,请求携带 X-API-Key。官方 E2B SDK 请使用 E2B 兼容接口,不能只修改 API 地址来调用这里的接口。

HTTP 基础地址:https://api.deepraxis.com/sandbox/v1。

端点

方法路径说明支持
POST/v1/templates预留模板构建● 支持
POST/v1/templates/{templateID}/builds/{buildID}开始模板构建◐ 部分支持
GET/v1/templates/{templateID}/builds/{buildID}/status查询构建状态● 支持
GET/v1/templates/{templateID}/files/{hash}检查构建文件○ 未支持
GET/v1/templates/{templateID}读取模板及构建● 支持
POST/v1/templates/tags设置构建标签● 支持
DELETE/v1/templates/tags删除构建标签● 支持
GET/v1/templates/{templateID}/tags列出构建标签● 支持
GET/v1/templates/aliases/{alias}解析模板名称● 支持
DELETE/v1/templates/{templateID}删除用户模板● 支持
POST/v1/sandboxes创建沙箱● 支持
POST/v1/sandboxes/{sandboxID}/upgrade升级为完整沙箱● 支持
GET/v1/sandboxes列出沙箱● 支持
GET/v1/sandboxes/{sandboxID}读取沙箱● 支持
PATCH/v1/sandboxes/{sandboxID}重命名沙箱● 支持
GET/v1/sandboxes/{sandboxID}/metrics沙箱指标● 支持
POST/v1/sandboxes/{sandboxID}/timeout设置超时● 支持
POST/v1/sandboxes/{sandboxID}/pause暂停沙箱● 支持
POST/v1/sandboxes/{sandboxID}/connect连接沙箱● 支持
DELETE/v1/sandboxes/{sandboxID}终止沙箱● 支持
GET/v1/templates列出模板● 支持
POST/v1/volumes创建卷● 支持
GET/v1/volumes列出卷● 支持
GET/v1/volumes/{volumeID}读取卷● 支持
DELETE/v1/volumes/{volumeID}删除卷● 支持
POST/v1/sandboxes/{sandboxID}/fork复制沙箱● 支持
POST/v1/sandboxes/{sandboxID}/snapshots创建快照● 支持
GET/v1/snapshots列出快照● 支持
DELETE/v1/snapshots/{snapshotID}删除快照● 支持
PUT/v1/sandboxes/{sandboxID}/network更新网络策略● 支持
GET/v1/sandboxes/{sandboxID}/logs读取沙箱日志● 支持
GET/v1/events/sandboxes/{sandboxID}读取沙箱事件● 支持
POST/v1/sandboxes/{sandboxID}/extend延长沙箱● 支持
GET/v1/sandboxes/{sandboxID}/processes列出进程● 支持
GET/v1/sandboxes/{sandboxID}/processes/{processID}/output读取输出● 支持
GET/v1/sandboxes/{sandbox_id}/files:list列出文件● 支持
GET/v1/sandboxes/{sandbox_id}/files读取文件● 支持
PUT/v1/sandboxes/{sandbox_id}/files写入文件● 支持
POST/v1/sandboxes/{sandbox_id}/files:makeDir创建目录● 支持
DELETE/v1/sandboxes/{sandbox_id}/files删除文件或目录● 支持
POST/v1/sandboxes/{sandbox_id}/commands运行命令● 支持
POST/v1/sandboxes/{sandboxID}/act操作手机屏幕● 支持
POST/v1/sandboxes/{sandboxID}/tasks启动任务● 支持
GET/v1/sandboxes/{sandboxID}/tasks/{taskID}/log读取任务日志● 支持

与官方的差异

  • 快照使用本平台 snap_ 开头的 ID,可作为创建沙箱的 templateID。旧供应商句柄不再接受。暂停的沙箱用「连接沙箱」恢复运行。
  • 仅提供本页声明的端点,webhooks 等未采纳的端点返回 404。
  • 开始模板构建:与官方行为存在差异
  • 检查构建文件:与官方行为存在差异
  • 创建沙箱:与 E2B 一致:不带 templateID 创建时使用默认的 base 模板;要用其他模板,从「列出模板」选取 templateID。每个沙箱创建时必须声明生命周期:Praxis 原生接口(请求头 X-Praxis-Face: own-v1)必须传 ephemeral,true 是一次性(从不暂停,结束即删除,用于跑任务),false 是持久(可暂停、快照、挂卷,用于长期使用的云电脑),缺省返回 INVALID_PARAMS;E2B 兼容接口用 autoPause 声明,true 为持久,false 或缺省为一次性。持久专属字段(autoPause:true、onExpire:pause、autoPauseMemory、autoResume、idleTimeout、retention、存储卷)必须配合 ephemeral:false。只有长期云电脑选持久。机器结束后再访问会返回 SANDBOX_EXPIRED(410),文件已不在,需新建沙箱。要保留结果,在原生接口创建时声明 outputs: [{ path }](最多 8 条绝对路径,目录或文件):沙箱结束时(供应商丢失和启动失败除外),每条打包成 .tar.gz 存进 File,事件接口的 killed 事件列出每条的 fileId 或没保留下来的原因;没声明的路径不保留,E2B 兼容接口拒绝 outputs。响应里的 ephemeral 回显所属类型。
  • 读取沙箱事件:按账本顺序读取一个沙箱的一生事件,默认最新在前。与其他读接口不同,它在沙箱已结束(killed / failed)之后仍然回答——机器没了,死因还能查。killed 事件的 eventData.terminationReason 是平台的原因(requested、lease_expired、max_running、provider_lost、start_failed、retention、admin、unknown),kill_reason 是 E2B 口径的分类(request、timeout、admin、orphaned、unknown);updated 事件带 expiresAt。分页用 offset、limit(1–100,默认 10)、orderAsc 与可重复的 types。判定不会回来的沙箱,文件和命令接口访问时返回 SANDBOX_EXPIRED(410)并带 terminationReason。

参数与字段的权威定义以 E2B 官方文档为准。

错误按 E2B 格式返回,参见错误;额度与响应头参见限流。