本仓库是 amla-sandbox Python 包的发布源。开发在 amlalabs 单体仓库 中进行;此仓库会在发布时更新。编译为 amla_sandbox.wasm 的 Rust 运行时位于 amla-sandbox-core;此 Python 包所构建的精确发布标签记录在 .mirror-deps.json 中。
amla-sandbox 是一个具有能力强制机制的 WASM 沙箱,用于 AI 智能体代码。智能体只能调用你明确提供的工具,并受你定义的约束限制。提供沙箱化的虚拟文件系统。无网络。无 shell 逃逸。
pip install amla-sandbox
无需 Docker。无需虚拟机。单个二进制文件,随处运行。
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",
)
带能力约束:
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 表面、框架集成和约束 DSL,请参阅 PyPI 页面 和 examples/ 目录。
沙箱在 WebAssembly 内运行,使用 WASI 以提供极小的系统调用接口。在 WASM 隔离之上,每个工具调用都要经过能力验证;访问是显式授予的,而不是隐式可用的。有关完整解释和权衡,请参阅上面的 快速开始 和上游 PyPI README。
对于大多数用户,建议从 PyPI 安装;wheel 包含预构建的 WASM 二进制文件。如果你想自己构建 wheel:
uv build
要重新生成打包在 wheel 中的 WASM 构件,请从 amla-sandbox-core 使用 .mirror-deps.json 中固定的标签进行构建,然后将结果放入 src/amla_sandbox/_wasm/amla_sandbox.wasm,再运行 uv build。
请参阅 CONTRIBUTING.md。向此镜像提交的拉取请求将在下次发布时被覆盖;请针对单体仓库提交,或在此处提交 issue。
Python 包代码采用 MIT 许可。捆绑的 Rust WASM 运行时采用 AGPL-3.0-or-later 或 BUSL-1.1 许可。