跳转到内容

在 Modal 沙箱上自托管

Modal 把每个 Session 作为一个云沙箱运行,并将预先创建的 Modal Volume v2 中按 Session 划分的子路径挂载到 /workspace。驱动在分离前同步该卷,并在这份持久状态之上重建过期的计算实例,因此工作区能在沙箱重启后存活。

Terminal window
MODAL_TOKEN_ID= # 必需
MODAL_TOKEN_SECRET= # 必需

驱动会动态导入 modal npm 包,因此它必须安装在 worker 进程中。Volume v2 必须事先存在——适配器以 createIfMissing: false 查找它,绝不隐式创建旧版卷,因为那会削弱配置好的持久性。

Modal 通过运行时宿主组合接入,而不是 SANDBOX_PROVIDER。使用 @open-managed-agents/managed-runtime-modal 提供的 createModalProvider、createModalManagedRuntime 或 createModalManagedRuntimeDriver:

const driver = createModalManagedRuntimeDriver({
leaseTtlMs: 90_000,
credentials: {
tokenId: process.env.MODAL_TOKEN_ID!,
tokenSecret: process.env.MODAL_TOKEN_SECRET!,
},
appName: "openma-workers",
image: "node:22-slim",
workspaceVolumeName: "openma-workspaces", // 预先创建的 Volume v2
});

按分配实例调节的参数走 createOptions——它接收分配上下文并返回任意 ModalSandboxCreateOptions:cpu、cpuLimit、memoryMiB、 memoryLimitMiB、gpu、timeoutMs、idleTimeoutMs、 encryptedPorts、h2Ports、unencryptedPorts、blockNetwork、 outboundCidrAllowlist、outboundDomainAllowlist、 inboundCidrAllowlist、cloud、regions、includeOidcIdentityToken、 experimentalEnableSnapshot。工厂还接受 client、runtimeEnvironment、 outputStore、outputKeyPrefix、credentialEgress、sessionInputs 和 readiness。

Harness 通道ama_worker、openma_supervised
suspendResume支持
工作区retained_runtime,基于持久 Volume v2 子路径
输出final_collect,持久
进程检查点无
凭证出口默认 unsupported/snapshot