Amla Sandbox提供基于WebAssembly的隔离bash环境,为AI Agent工作流解决了代码执行的安全问题。
这个仓库是 amla-sandbox Python package 的发布源。开发工作在 amlalabs monorepo 中进行;每次发布时,这个仓库都会同步更新。编译为 amla_sandbox.wasm 的 Rust runtime 位于 amla-sandbox-core;构建此 Python package 时所对应的确切 release tag 记录在 .mirror-deps.json 中。
amla-sandbox 是一个面向 AI Agent 代码、具备 capability 强制管控能力的 WASM sandbox。Agent 只能调用你明确提供的工具,并受到你所定义的约束。它提供沙箱化的虚拟文件系统,不允许访问网络,也无法逃逸到 shell。
pip install amla-sandbox
不需要 Docker,不需要 VM。只需一个 binary,即可在任何地方运行。
from amla_sandbox import create_sandbox_tool
sandbox = create_sandbox_tool()
# JavaScript
sandbox.run("console.log('hello'.toUpperCase())", language="javascript")
# Shell
sandbox.run("echo 'hello' | tr 'a-z' 'A-Z'", language="shell")
# With tools
def get_weather(city: str) -> dict:
return {"city": city, "temp": 72}
sandbox = create_sandbox_tool(tools=[get_weather])
sandbox.run(
"const w = await get_weather({city: 'SF'}); console.log(w);",
language="javascript",
)
还可以添加 capability 约束:
from amla_sandbox import Sandbox, ToolCallCap, ConstraintSet, Param
sandbox = Sandbox(
capabilities=[
ToolCallCap(
method_pattern="stripe/charges/*",
constraints=ConstraintSet([
Param("amount") <= 10000,
Param("currency").is_in(["USD", "EUR"]),
]),
max_calls=100,
),
],
tool_handler=my_handler,
)
完整的 API、framework 集成方式以及 constraint DSL,请参阅 PyPI 页面和 examples/ 目录。
sandbox 运行在 WebAssembly 内部,并通过 WASI 将 syscall 接口面降至最低。在 WASM 隔离的基础上,每一次工具调用都必须经过 capability 校验;访问权限需要被明确授予,而不是默认开放。完整说明及相关权衡,请参阅上面的快速入门内容和上游 PyPI README。
对大多数用户而言,建议直接从 PyPI 安装;wheel 中已经包含预构建的 WASM binary。如果你想自行构建 wheel:
uv build
如果要重新生成打包在 wheel 内的 WASM artifact,请使用 .mirror-deps.json 中锁定的 tag,从 amla-sandbox-core 进行构建,然后将生成结果放到 src/amla_sandbox/_wasm/amla_sandbox.wasm,最后运行 uv build。
请参阅 CONTRIBUTING.md。针对这个镜像仓库提交的 Pull Request 会在下一次发布时被覆盖;请将 Pull Request 提交到 monorepo,或者在这里创建 issue。
Python package 代码采用 MIT 许可证。随包提供的 Rust WASM runtime 采用 AGPL-3.0-or-later OR BUSL-1.1 双重许可。