跳到正文
DEV Community· Sandscale·· 7 小時前AI 評分58

Sandscale 發佈開源快速入門,示範在 Firecracker microVM 執行 AI 智能體程式碼

Run your AI agent's code in a microVM

AI 導讀

Sandscale 發佈開源專案 sandscale/agent-quickstart,示範把 AI 智能體撰寫的程式碼放進每次新建的 Firecracker microVM sandbox 執行,完成後即丟棄 sandbox。

正文

Today we're publishing a quickstart for one job: taking code an AI agent wrote and running it somewhere other than your laptop. It's a small open-source repo, sandscale/agent-quickstart, that runs each piece of agent-written code in a fresh Sandscale sandbox, a Firecracker microVM with its own kernel, and throws the sandbox away when the run ends.

It works on the Free plan. You need Node.js 22, a Sandscale account and an API key. The code targets @sandscale/sdk 1.0.0, and it's MIT licensed.

What's in the quickstart

The repo has three ways in, all doing the same thing:

  • run.mjs runs any .py or .js file in a new sandbox and streams the output back to your terminal.
  • agent/sandbox-tool.mjs is a run_code tool: a plain JSON Schema definition plus a handler. Hand the schema to any model that supports tool calling, and when the model asks to run code, the handler runs it in a sandbox and returns the exit code, stdout and stderr.
  • curl/run.sh does it with four REST calls and no SDK, for anyone not on Node.

It comes with two sample programs that stand in for agent output. untrusted.py reports what it can see: the kernel it's running on, the names of the environment variables it has, whether your ~/.ssh and ~/.aws folders exist, and whether it can reach the internet. runaway.py never ends, so you can watch the run timeout stop it.

The whole run is four SDK calls:

const box = await sandscale.sandboxes.create({ template: 'builtin:python', timeoutSeconds: 300 });
await sandscale.sandboxes.writeFile(box.id, '/workspace/main.py', code, { region: box.region });
const run = await sandscale.sandboxes.run(box.id, ['python3', 'main.py'], { region: box.region, timeoutSeconds: 30 });
await sandscale.sandboxes.stop(box.id, { region: box.region }); // in a finally block

run returns the exit code, output, duration, and whether the command timed out or ran out of memory. timeoutSeconds on the sandbox stops it even if your script crashes before the finally runs.

Why a microVM per run

Code from a model is code nobody has reviewed yet. The model may be wrong, and it may also be following instructions it picked up from a README, an issue comment or a dependency's install script. That's prompt injection, and the agent can't reliably tell those instructions apart from yours. So the question isn't whether the code is trustworthy. It's what the code can reach when it isn't.

Running it on your laptop means it can reach your files, your environment and anything you're signed in to. Running it in a container is better, but a container shares the host's kernel, so the boundary depends on getting every mount, capability and syscall filter right. A microVM gives each run its own kernel. That's a stronger boundary than a shared-kernel container. It isn't a guarantee, and we don't claim it is.

Two more things matter as much as the kernel:

  • A fresh box per run. Nothing from an earlier run is there, so one bad run can't leave something behind for the next.
  • The network. Firecracker itself doesn't filter egress, so network policy is a separate layer. A Sandscale sandbox can reach only what your plan, your organization's policy and your egress allowlist allow.

Containers, gVisor or Firecracker goes through the trade-offs in detail, and Running untrusted pull request code applies them to PR tests.

How billing works

You pay for awake vCPU-hours: one vCPU running for one hour while the box is awake. A box that is paused, or idle between tool calls, doesn't count. The example on our pricing page: a 2 vCPU agent box open for 10 hours and awake 10% of the time uses 2 awake vCPU-hours.

That matters for agents because they spend a lot of their time waiting on the model, not computing. There are exceptions. Always-on workspaces are a flat monthly price, dedicated cores bill by wall clock, and storage above the allowance is billed. Awake-time billing for agent sandboxes works through the arithmetic.

The Free plan includes 100 awake vCPU-hours a month, up to 3 sandboxes at once, and up to 2 vCPU each. Paid plans are on the pricing page.

What comes with it

The quickstart only uses sandboxes, but every plan, Free included, also has:

  • Vault, so a run can get a secret as an environment variable without the value passing through your code, the API's answer or a log. See Give a run a secret.
  • Human approvals, so a tool call can wait for a person before it runs.
  • A hash-chained audit log that every plan can read. Team and up can export it.
  • DLP on prompts and MCP tool calls, which stops a call when it matches a credential pattern. It doesn't scan files or output inside the sandbox.

Anything you put inside the sandbox, a Vault secret included, is readable by the code running there. Give runs narrow, short-lived credentials, or none.

What it doesn't do yet

  • US only. Sandscale runs in N. Virginia on AWS. Europe (Frankfurt) is coming soon.
  • No GPU sandboxes, and no Windows or macOS sandboxes.
  • No certification. We don't hold SOC 2 or ISO 27001. The audit export is evidence for your own assessments.
  • Early access. There's no availability commitment or service credit yet.
  • SDKs. The TypeScript SDK is out, and the Python SDK is coming soon. The quickstart's REST script works from anything that can make HTTP calls.

Where to go next

If you're weighing options, our comparisons with E2B, Daytona and Modal say where each of them is the better pick.

Try it

  1. Sign up free at cloud.sandscale.dev and create an API key in your account settings.
  2. Clone sandscale/agent-quickstart, put the key in .env, and run node --env-file=.env run.mjs examples/untrusted.py.
  3. Swap in code your own agent wrote.

Tell us where the quickstart doesn't do what it says, or what stops you from running agent code on it. Open an issue on the repo or write to us from the contact page.

來源:DEV Community · dev.to