dsh-flutter-sandbox:在 workspace-write 沙箱里跑 Flutter 与 Dart

前言

DeepSeek Harness(DSH)在 workspace-write 模式下,默认只允许命令写入当前会话工作区和 /tmp。Flutter 与 Dart 工具链每次运行都会往 SDK 缓存、pub 缓存、Gradle 目录等路径写文件,连 flutter --version 也可能因只读文件系统失败。社区插件 dsh-flutter-sandbox(维护者 liyuqian,GitHub 分类 admin-security)在保持其余路径仍受保护的前提下,为沙箱额外开放 Flutter/Dart 生态常用的可写目录。

这是什么

dsh-flutter-sandbox 是 DSH 插件:用自定义 sandbox provider 替换 dsh-base 自带的 @deepseek-ai/dsh-sandbox-local,使 workspace-write 下的 shell 命令还能写入 Flutter SDK、PUB_CACHE、Dart/Flutter 配置与 Android 构建相关目录。read-only 与 danger-full-access 模式不受影响;模型会在上下文中被告知这些额外可写路径。

典型失败现象(未装插件时)类似:

update_engine_version.sh: line 71: .../flutter/bin/cache/engine.stamp.tmp: Read-only file system

核心功能

插件在检测到目录存在时,为下列路径授予写权限(其余仍受沙箱保护):

目录 原因
Flutter SDK($FLUTTER_ROOT 或从 PATH 上的 flutter 解析) 每次运行会更新 bin/cache
$PUB_CACHE 或 ~/.pub-cache 包下载
~/.dart-tool、~/.dartServer 遥测与分析服务缓存
~/.flutter、$XDG_CONFIG_HOME/flutter(~/.config/flutter) Flutter 设置
$GRADLE_USER_HOME 或 ~/.gradle、~/.android Android 构建

实现上,bundle patch 禁用 dsh-base 的 sandbox 行并插入 sandbox-flutter(继承自 stock provider)。每次 workspace-write 调用时,由 stock provider 构建 runner 命令,再在命令前的 -- 之前按 runner 类型插入 grant:

  • bubblewrap(Linux):--bind <dir> <dir>
  • Landlock(Linux):--rw <dir>
  • Seatbelt(macOS):(allow file-write* (subpath "<dir>"))

安装与启用

在对应 profile 下安装(资料中的示例为 tui profile):

dsh plugin --profile tui add github:liyuqian/dsh-flutter-sandbox

其他 profile 将 tui 换成 --profile web 或你的 profile 名。卸载:

dsh plugin --profile tui remove dsh-flutter-sandbox

插件以当前 dsh 进程权限运行;安装前建议在 GitHub 查看源码与 MIT 许可证,自行评估是否适合你的环境。

配置

默认无需改配置。若要关闭 Flutter 相关目录或增加自定义可写根路径,在 profile 的 cordis.patch.yml(路径:~/.dsh/profiles/<profile>/cordis.patch.yml)中覆盖插件行:

- id: sandbox-flutter
  config:
    flutter: true               # 启用上文列出的 Flutter/Dart/Gradle/Android 目录
    extraWritableRoots:         # 额外绝对路径
      - /home/me/.cocoapods

stock provider 的 runnerCommand、runnerFailureSignatures、probeTimeoutMs 同样可在此配置。

典型用法与注意

  1. 安装插件后,在 DSH 会话里照常通过 shell 执行 flutter、dart pub、gradle 等;这些工具经 shell 发起的写操作会命中扩展后的可写目录。
  2. 仅 shell 命令受益。 DSH 自带的文件 write/edit 工具仍单独校验可写路径,不会自动放开 SDK 或 ~/.pub-cache;需要时仍可按流程申请权限。
  3. 不支持 Windows。 ACL runner 无法追加额外目录,受限命令会明确报错,而不是在无 grant 情况下静默执行。
  4. 依赖 stock runner 参数布局。 若 dsh 发行版改变布局,插件会报 unexpected sandbox argv layout 并拒绝在非预期状态下运行;README 注明在 dsh 0.1.1-rc.2 上测试过。package.json 中插件版本为 0.1.0,peer 依赖 @deepseek-ai/dsh-sandbox-local >=0.1.1-rc.2。
  5. Pub workspace。 在 workspace 子包里执行 flutter pub get 会向 workspace 根目录写入;DSH 会话应从该根目录启动。

开发与局限小结

仓库内可用 npm test 跑测试(覆盖根目录发现与各 runner 的 grant 插入,无需本地安装 dsh)。

DSH 生态强调「一切皆插件」;SkillHub 等社区目录是独立站点,与 DeepSeek / 幻方无官方从属关系。若你在 Harness 里用智能体做 Flutter 项目而沙箱写权限卡在 SDK 与缓存路径上,dsh-flutter-sandbox 是在不切换到 danger-full-access 的前提下补齐常见写路径的一种做法。

  • 目录页:https://www.skillhub.cn/plugins/liyuqian/dsh-flutter-sandbox
  • GitHub:https://github.com/liyuqian/dsh-flutter-sandbox
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye