iii-sandbox
它能做什么
在短暂存在的隔离虚拟机中运行代码,使来源不明的代码无法触及你的主系统。它适用于构建会运行自己未编写代码的 AI 智能体或工具的开发者。
适用场景
- ✓当智能体需要运行你并不完全信任的代码的时候。
- ✓当你想在一个用完即弃的干净环境中测试一段代码的时候。
- ✓当你需要在一个隔离沙盒中运行多条命令或编辑多个文件的时候。
技能链接
https://github.com/iii-hq/iii/blob/main/crates/iii-worker/src/sandbox_daemon/skills/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在隔离沙盒中运行这段不可信的 Python 代码,并把输出给我看。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能会启动一个小型虚拟机,在其中运行代码或命令,并返回输出。对于多步骤工作,沙盒会在多次调用之间保持运行,之后会被停止,其临时文件也会被丢弃。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
iii-sandbox
The iii-sandbox worker boots ephemeral libkrun microVMs and runs code inside them, isolated from the host. Each sandbox boots in a few hundred milliseconds, runs commands or file operations scoped to the engine it lives on, and is reaped when idle; the overlay filesystem is discarded on stop. Its sandbox::* functions are called like any other iii function.
There are two ways in. sandbox::run is the fast path: it boots a VM, runs a code snippet, captures stdout/stderr, and tears the VM down in a single call. For multi-step work — several commands, multiple files, or inspecting a VM between steps — use the sandbox::create → sandbox::exec / sandbox::fs::* → sandbox::stop lifecycle and carry the returned sandbox id across calls.
Prerequisites: enable iii-sandbox under engine.workers (or the five-worker allowlist of a
directly supervised engine), and provide hardware virtualization (Apple Silicon, or /dev/kvm on
Linux). Intel Macs and Windows cannot boot sandboxes.
Get the contract from the engine
This page tells you WHEN and HOW to use the sandbox; the engine is the source of truth for every function's exact arguments and responses. Before you call any sandbox::* function, fetch its contract and build your payload from that — do not guess field names, types, or formats from memory:
engine::functions::info { function_id: "sandbox::<fn>" }
(e.g. { function_id: "sandbox::fs::write" }). The returned schema is authoritative; this skill never restates it.
Running an iii worker inside a sandbox
To author an iii worker (read the iii skill first), you write the worker code into the sandbox, install its deps, and run it as a process there — but the worker must still join the HOST engine bus to be useful.
- Reaching the host engine: enable networking when you create the sandbox (the field is in the
sandbox::createcontract — fetch it), AND set the worker's engine-URL env (III_ENGINE_URL, e.g.ws://localhost:49134) IN THEsandbox::createenv— NOT later at exec/run time. The localhost→host rewrite happens ONLY for the create-timeenv: alocalhost/127.0.0.1engine URL set there is rewritten to the per-sandbox gateway so the worker reaches the host bus. The samelocalhostURL passed atsandbox::exectime is NOT rewritten — it points at the sandbox's own loopback, the worker silently fails to connect, and you will waste turns debugging TCP. So: put the engine URL in the createenv; the worker process inherits it already rewritten. - Run it backgrounded, never as a foreground
exec: starting the worker withsandbox::exec "node index.mjs"blocks and times out (S200 exec timed out), because the process never returns. Launch it detached (… &,nohup, orsandbox::runshell mode) so the exec call returns while the worker keeps running — see the serialized-exec boundary below. - Find the result: once the worker connects, its functions appear in
engine::functions::listand anyhttptrigger it binds is served by the Composehttpworker; verify endpoints withweb::fetch, notcurl. - EPHEMERAL by nature: a worker hosted in a sandbox dies when the sandbox is stopped or reaped (the overlay is discarded). That is fine for a demo, test, or one-off. Declare a long-lived worker as a Compose
containerinstead of hosting it in a sandbox.
When to Use
- Execute untrusted or LLM-generated code without exposing the host.
- One-shot "code in, stdout out" — reach for
sandbox::run. - Spin up an ephemeral build worker, integration-test fixture, or throwaway iii worker.
- Read, write, search, or edit files inside an isolated filesystem.
Boundaries
- A sandbox is for running code and build steps, NOT for hosting a long-lived server. To expose an HTTP API or any always-on endpoint, author an iii worker and register a trigger for it (an
httptrigger is served by the Composehttpworker) — do NOT start a server process (express,http.createServer, a frameworklisten()) inside the sandbox. A server you start here is not routed by iii, is unreachable as an iii endpoint, and as a foreground process hangs the exec slot until it times out. If the task is "build an iii worker," the deliverable is registered functions plus a trigger, not a running server. - Not for long-lived services or durable state — the overlay is wiped on stop. Use a regular worker for daemons and the Compose
stateworker for persistence. - Bootable images are catalog NA
常见问题
哪些电脑能运行它?
Apple Silicon 的 Mac,或支持硬件虚拟化的 Linux 机器。Intel 的 Mac 和 Windows 无法启动这些沙盒。
之后它会保留我的文件吗?
不会。沙盒停止时,临时文件系统会被丢弃。
我需要了解函数的细节吗?
不需要。该技能在调用之前会从引擎获取每个函数的确切参数。
详情
作者的原始描述
Ephemeral microVM sandboxes for running untrusted or agent-generated code in isolation — a one-call run path, a create/exec/stop lifecycle, and a set of filesystem operations.
repo: iii-hq/iii
热度
- GitHub 星标
- 19k
- 排名
- #10485
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
configuration
19k让你的智能体设置一个共享的命名配置值注册表,并按模式进行检查,使工作进程可以读取并响应变化。
iii
19k教你的智能体了解 iii 工作进程如何运作,使其可以先检查已有的功能,再构建新的工作进程来添加能力。
iii-observability
19k帮你的智能体使用 OpenTelemetry 为 iii 引擎添加追踪、结构化日志、指标和告警,让你看清系统正在发生什么。
iii-stream
19k说明用于实时数据流的 iii-stream 工作进程。它已被弃用,并将在即将发布的版本中移除,因此请规划迁移。