drscrewdriver/dsh-seatbelt-sandbox ↗★ 1
dsh-seatbelt-sandbox
Seatbelt (libsandbox) sandbox provider for the DeepSeek Harness sandbox seam on macOS: a cordis plugin that replaces @deepseek-ai/dsh-sandbox-local's seatbelt rung via a prebuilt seatbelt-run launcher — no dsh source changes, no PR required
安装
此插件尚未提供可验证的 bundle,或兼容性检查未通过。请先阅读仓库说明。 阅读完整 README ↗
说明文档
阅读完整 README ↗sandbox-policy / bash / fs-sandbox 等其余插件与配置不动
完整示例见 [examples/cordis.yml](https://github.com/drscrewdriver/dsh-seatbelt-sandbox/blob/91ffb070772c1269acb515bbee993e829232f934/examples/cordis.yml)。消费方(`@deepseek-ai/dsh-bash-sandbox`、`@deepseek-ai/dsh-fs-sandbox` 等)只依赖 `ctx.sandbox` 服务,对后端实现零感知。
`loaderPath` 仅当二进制未随包分发(例如单独拷贝到固定路径、或需要跨架构指定)时使用;缺省时 `launcherPath()` 按 `process.platform + process.arch` 解析包内 `bin/darwin-/seatbelt-run`。
## loader CLI 契约
seatbelt-run
[--]
seatbelt-run --self-test
- profile 走文件传递(规避 ARG_MAX);可选 `--` 分隔符与 dsh `confine` 惯例对齐,且与 inferglow `seatbelt-loader
` 契约兼容(无 `--` 形态同样可用,二进制可互换)。
- 失败统一退出 **125**(对齐 dsh landlock launcher 约定),stderr 前缀 `seatbelt-run: `;沙箱 denial 是内核方言 `operation not permitted`,与 loader 失败可区分。
- `--self-test` 应用空 profile `(version 1)`,退出 0 表示 libsandbox API 可用——插件的功能探测。
## 与官方 seatbelt rung 的行为差异
| 维度 | 官方 `@deepseek-ai/dsh-sandbox-local` | 本插件 |
|------|--------------------------------------|--------|
| 执行器 | `sandbox-exec` CLI(已弃用) | `seatbelt-run`(直调 libsandbox,跨生态共享契约) |
| 探测 | 真实 read-only profile + `true` | `--self-test`(空 profile,与 inferglow/Python 生态一致) |
| denial 方言 | `operation not permitted` | 相同 |
| runner 失败签名 | `sandbox-exec: `(无退出码门控) | `seatbelt-run: ` + `allowedExitCodes: [125]`(exit-gated,更强) |
| enforcement | full | full(SBPL deny file-write* 按构造保证) |
| 探测失败 | fail-closed `SANDBOX_UNAVAILABLE` | 相同 |
| SBPL 生成 | `seatbeltProfileArgs`(dsh 内部) | 本包 `sbpl.ts`(复制上游语义,方言测试 pin 等价) |
| profile 文件 | 内联 `-p` 传递 | 临时文件(provider 级缓存 + dispose 清理) |
## 契约跟踪责任(升级注意)
本插件通过 `peerDependencies` 锁定 `@deepseek-ai/cordis` 与 `@deepseek-ai/dsh-sandbox`。dsh 上游若演进 `ConfinedArgv` / `SandboxPolicy` / `SandboxProvider` 契约,需同步更新 `src/provider.ts`(契约变化集中于该单文件);`src/sbpl.ts` 的 `writableRoots` / `seatbeltProfileText` 语义来自 dsh 的 `roots.ts` / `profiles.ts`(BSD-3-Clause,来源已标注),上游变更时同步镜像并由 `tests/sbpl.test.mjs` 的方言断言兜底。
## 测试
```sh
npm test # 单元测试任意平台可跑;macOS e2e 自动跳过
npm run build:native && npm test # macOS 上跑完整套件(真实内核双向断言)
- 单元(
tests/sbpl.test.mjs、tests/provider.test.mjs):SBPL 方言、argv 组装、profile 缓存/清理、探测缓存、fail-closed。 - macOS e2e(
tests/seatbelt.e2e.mjs):read-only deny-write 不落盘 +operation not permitted、/dev/null 可写、workspace-write 双向断言、temp 区授权、坏 profile → 125 +seatbelt-run:。 - 装配集成:
examples/cordis.yml替换后,ctx.sandbox.confine()走新 provider,bash 沙箱的[sandbox: file access denied …]归因基于本插件的 denial 方言正确工作。
发布前验收清单(macOS)