打开文档导航

WASM 与 native 两条执行 lane

一句话

Pysolate 的 WASM lane 只接纳匹配已绑定 shard 资格面的请求;native sandbox 提供更宽的本地 CPython 兼容性 lane,但仍需显式 image/feature contract。两条 lane 服从同一 Host authority 原则,artifact、execution、evidence 和 cleanup 实现则不同。

先看一个例子

两份 Agent 程序都要处理 JSON。第一份只用标准库、输入输出都是 portable value;第二份需要当前 WASM shard 没有证明支持的 package,或者依赖显式 workspace/process state。

把第二份程序硬塞进 WASM,可能在运行中途才发现不兼容。把所有程序都放进 native container 又会放弃更窄的执行面,并支付 image、container、RPC 和 cleanup 成本。

Pysolate 先由 Host 判断哪条 lane 的已验证 contract 覆盖当前请求,而不是让 Guest 随便选择 backend。

真实机制

WASM lane

Wazero backend 执行 CPython-WASI artifact。Host 在启动前核对 request、requirements、execution profile、artifact/manifest identity、qualified imports 和 workspace admission。每次普通 Run 创建 fresh Guest module;capability call 通过 Wazero host function 回到本次 attempt 的 Broker。

这条 lane 的优势是执行面封闭,并能把 artifact identity 与已验证 import qualification 绑定,也能接入 prepared runtime/private-COW 等受限机制。Qualification 只证明窄 surface,不证明任意 portable 程序都能运行。“轻量”描述的是它不需要为每次请求建立完整 OCI/runsc lane,不是对所有 workload 的性能定理。

Prepared Family 与 current source-patch plugin 都落在这条 Wazero/exact-Guest surface 上,但它们不是默认 router 功能。Family 需要显式 numpy-core artifact/config;pure scalar pass 需要 semantic analysis、authority-free transform Guest 和 fresh final Guest。这里的 exact Guest 是身份与 correctness gate,不是“任意 Python 都能优化”的新 backend。

Native lane

Native backend 为一次 attempt 验证 OCI image config 和 rootfs identity,建立 readonly root、受限资源、namespace、可选 workspace mount,以及本次执行专属的 Unix-socket capability channel。Container 中的 Python 通过私有 HTTP/RPC 调 Host Broker;credential、execution ID、Plan identity、call ID 和 expiry 都由 Host registry 绑定。

执行结束后,native owner 收集 bounded output、receipt、workspace 与 resource evidence,撤销 channel,删除 runsc container/state,释放 Lease 并清理 scratch。Native runner 的 CPython surface 更宽,但被 placement 选中不证明任意包或任意 Python 程序一定成功。

共享原则与独立 owner

两条 lane 共享:

  • sealed capability Plan、Grant、Broker 和 Host-authored receipt;
  • 每次 Run/attempt 的 frozen identity 与预算;
  • external effect 不由 Python syntax 或 backend 自行授权;
  • fresh execution、terminal disposition 和 non-replay 规则。

它们不共享字节级实现。WASM identity 绑定 WASM artifact、manifest、profile 和 shard;native identity 绑定 OCI image、rootfs、execution、RPC channel 与 cleanup。Response/evidence schema 和可观察资源也不完全相同。

为什么重要

技术上: Backend compatibility 与 authority 分开处理。Native 扩大可运行表面时,不会绕过 Broker;WASM qualification 不足时,也不会靠运行中的普通异常猜测 fallback。

产品和业务上: 同一 Agent Program/CapabilitySpec 可以服务不同执行环境。平台可将已证明 portable 的任务放入窄 WASM lane,把确实需要 native 的任务送入隔离更重的兼容性 lane,并清楚记录选择原因和成本来源。

不能推出什么

  • WASM 与 native 不是语义、response 或 evidence 完全等价的 runner。
  • 当前没有 production-grade sandbox security、性能或任意 Python compatibility 证明。
  • Native RPC 的 completed-response replay 只约束一个 channel 中的 exact call ID,不代表整次 Python Run 可重放。
  • Package profile 的构建支持不表示默认 placement 已能自动选择所有 shard。
  • Prepared Family 或 source pass 可在 Wazero 中运行,不表示 placement 会自动选择它们,也不把它们推广到 native/general Python。

术语卡

  • WASM lane:由 Wazero 执行已验证 CPython-WASI artifact 的路径。
  • Native lane:通过 OCI/runsc 与私有 Host RPC 执行 native CPython 的路径。
  • Backend:承载一次 physical execution 的具体运行实现。
  • Capability RPC:native Guest 回到 Host Broker 的受控调用通道。
  • Cleanup evidence:记录 container、channel、workspace lease 等终结情况的 Host evidence。

继续阅读