沙箱
為您的指令碼與 AI 代理執行程式碼而設計的隔離 Linux microVM。每個約一秒就能啟動,可執行 Python、Node.js 或 bash,並從與伺服器相同的餘額按秒計費。
什麼是沙箱
一台小型 Linux 機器:透過 API 或 MCP 建立,用幾秒或幾天,然後刪除。對外網路可用(pip install、npm install、git clone)。沒有對內埠,也沒有 SSH:指令和檔案都透過 API 傳遞。內建:帶 pip 的 Python 3.12、帶 npm 的 Node.js 22、bash、git 和 curl。
兩種模式
方案
| 方案 | vCPU | RAM | 磁碟 | 網路 | 每小時 | 持久,每月上限 |
|---|---|---|---|---|---|---|
| micro | 0.25 | 512 MB | 3 GB | 50 Mbit/s | $0.0165 | $9.03 |
| small | 0.5 | 1 GB | 5 GB | 100 Mbit/s | $0.033 | $18.07 |
| standard | 1 | 2 GB | 10 GB | 200 Mbit/s | $0.066 | $36.14 |
| plus | 2 | 4 GB | 15 GB | 300 Mbit/s | $0.132 | $72.27 |
| pro | 4 | 8 GB | 20 GB | 400 Mbit/s | $0.264 | $144.54 |
| max | 8 | 16 GB | 40 GB | 500 Mbit/s | $0.528 | $289.08 |
按所選方案的 vCPU 和 RAM 付費:每 vCPU 小時 $0.040,每 GiB 小時 $0.013。即時價格無需權杖:GET /sandboxes/tariffs。
需要了解的限制
單一指令最長執行 55 秒;更長的工作以背景任務執行,由您輪詢結果。每次請求的檔案上限為 5 MB,更大的檔案(最大 2 GB)透過一次性的下載與上傳連結傳輸。一個帳戶最多可同時執行 20 個沙箱與 2 條指令。
環境變數
以 env 傳遞機密與設定。在 create 時設定的變數適用於沙箱中的每條指令;在 exec 或 run 中設定的變數只對該次呼叫生效,並覆寫沙箱的值。最多 64 個變數,每個值 32 KB,總計 64 KB。值以加密方式儲存,API 絕不會傳回,也不會寫入記錄檔:回應中只顯示名稱(env_keys)。
API=https://api.eqvps.com/api/v1/eqvps
AUTH="Authorization: Bearer $EQVPS_API_KEY"
# env for the whole sandbox (only the names come back, as env_keys)
SB=$(curl -s -X POST $API/sandboxes -H "$AUTH" -H "Content-Type: application/json" \
-d '{"tariff":"small","env":{"DB_URL":"postgres://user:pass@db/app","MODE":"test"}}' | jq -r .id)
# env for one call, merged over the sandbox env
curl -s -X POST $API/sandboxes/$SB/exec -H "$AUTH" -H "Content-Type: application/json" \
-d '{"command":"echo $MODE $RUN_ID","env":{"RUN_ID":"42"}}'消費上限
預設情況下沙箱沒有消費上限。您可以在控制台或透過 PUT /sandboxes/budget 設定每日和每月上限。達到上限後,新沙箱會收到 429 budget_exceeded,執行中的臨時沙箱會被刪除,持久沙箱會暫停並保留磁碟。當您提高上限或進入新的一天或一個月(UTC)後,它們會恢復執行。
# daily cap $5, monthly cap $50 (null = no cap)
curl -s -X PUT $API/sandboxes/budget -H "$AUTH" -H "Content-Type: application/json" \
-d '{"daily_usd":5,"monthly_usd":50}'
# spent today / this month and when the caps reset (UTC)
curl -s $API/sandboxes/budget -H "$AUTH"快速開始:MCP(Claude Code、Cursor 及其他用戶端)
只需連線一次 MCP 伺服器,之後用日常語言吩咐代理即可。沙箱工具:create_sandbox、run_code、exec_command、get_task、kill_task、get_upload_url、get_download_url、list_sandboxes、get_sandbox、kill_sandbox、sandbox_pricing。
claude mcp add --transport http eqvps https://mcp.eqvps.com/mcp \
--header "Authorization: Bearer $EQVPS_API_KEY"建立一個小沙箱,用 Python 執行 print(2 + 2),把輸出給我看,然後刪除這個沙箱。快速開始:從 Python 和 Node.js 呼叫 REST
不需要額外安裝套件。把權杖放進環境變數 EQVPS_API_KEY(取得方式請見「連接您的帳戶」)。
# first_sandbox.py — Python 3.8+, standard library only
import json, os, urllib.request
API = "https://api.eqvps.com/api/v1/eqvps"
KEY = os.environ["EQVPS_API_KEY"]
def call(method, path, body=None):
req = urllib.request.Request(API + path, method=method,
data=json.dumps(body).encode() if body is not None else None,
headers={"Authorization": "Bearer " + KEY,
"Content-Type": "application/json", "Accept": "application/json"})
with urllib.request.urlopen(req, timeout=90) as r: # HTTPError on 401/402/…
return json.loads(r.read() or b"{}")
sb = call("POST", "/sandboxes", {"tariff": "small"})
try:
r = call("POST", f"/sandboxes/{sb['id']}/run",
{"language": "python", "code": "print(2 + 2)"})
print(r["exit_code"], r["stdout"]) # 0 4
finally:
call("DELETE", f"/sandboxes/{sb['id']}")// first_sandbox.mjs — Node.js 18+ (built-in fetch), run: node first_sandbox.mjs
const API = "https://api.eqvps.com/api/v1/eqvps";
const KEY = process.env.EQVPS_API_KEY;
async function call(method, path, body) {
const r = await fetch(API + path, {
method,
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json", Accept: "application/json" },
body: body ? JSON.stringify(body) : undefined,
});
const data = await r.json();
if (!r.ok) throw new Error(`${r.status} ${data.error ?? ""} ${data.message ?? ""}`);
return data;
}
const sb = await call("POST", "/sandboxes", { tariff: "small" });
try {
const r = await call("POST", `/sandboxes/${sb.id}/run`, { language: "node", code: "console.log(2 + 2)" });
console.log(r.exit_code, r.stdout); // 0 4
} finally {
await call("DELETE", `/sandboxes/${sb.id}`);
}Python 與 TypeScript SDK
偏好使用函式庫?Python 與 TypeScript 套件封裝了相同的 REST 呼叫,會自動重試 429 與 503,並在區塊結束時一定刪除沙箱。安裝與使用:
# pip install -U eqvps https://pypi.org/project/eqvps/ (0.2.0+ for env)
# "eqvps sandbox create" = Sandbox.create() here · create_sandbox in MCP · POST /sandboxes in REST (no CLI)
from eqvps import Sandbox
# EQVPS_API_KEY from the environment; env = secrets for your code, stored encrypted
with Sandbox.create(tariff="small", env={"DB_URL": "postgres://user:pass@db/app"}) as sb:
r = sb.run("print(2 + 2)")
print(r.stdout, r.exit_code) # "4\n" 0
sb.upload("/root/data.csv", "a,b\n1,2\n")
print(sb.exec("wc -l /root/data.csv").stdout)
print(sb.exec("echo $RUN_ID", env={"RUN_ID": "42"}).stdout) # env for one call
# the sandbox is deleted when the block exits, also on errors// npm i @eqvps/sdk@latest https://www.npmjs.com/package/@eqvps/sdk (0.2.0+ for env)
import { Sandbox } from "@eqvps/sdk";
// EQVPS_API_KEY from the environment; env = secrets for your code, stored encrypted
await Sandbox.with({ tariff: "small", env: { DB_URL: "postgres://user:pass@db/app" } }, async (sb) => {
const r = await sb.run("print(2 + 2)");
console.log(r.stdout, r.exit_code); // "4\n" 0
console.log((await sb.exec("echo $RUN_ID", { env: { RUN_ID: "42" } })).stdout); // env for one call
}); // deleted afterwards, also on errors
評論
目前還沒有評論。歡迎成為第一位。