dsh-unsandboxed-winbash:在 Windows 上爲 DSH 提供沙箱外的 Git Bash

前言

DeepSeek Harness(DSH)在 Linux 和 macOS 上可以通過 dsh-tool-bash 或 dsh-bash-sandbox 給智能體提供 bash。在 Windows 上,@deepseek-ai/dsh-base 會同時禁用這兩個工具;即便手工啓用,Git Bash(MSYS2)也往往在文件沙箱裏起不來——受限 token 無法創建 MSYS 信號處理所需的命名管道。結果是智能體在 Windows 上缺少一套可用的 Unix 風格 shell 工具鏈。

社區插件 dsh-unsandboxed-winbash(維護者 xswt442-cmd,分類 admin-security)針對上述限制:向會話新增 winbash 工具,在用戶自安裝的 Git for Windows 上執行命令,並明確在沙箱之外運行。下面介紹它的定位、能力、安裝方式與安全邊界。

這是什麼

dsh-unsandboxed-winbash 是僅面向 Windows(win32)的 DSH 工具插件。它不替換 DSH 自帶的 pwsh、fs 或權限相關服務,只增加名爲 winbash 的工具:用 Git Bash 的 bash -c 跑命令,修好 MSYS 相關的 PATH,並把 stdout、stderr 與退出碼返回給調用方。

npm 包名與倉庫名均爲 dsh-unsandboxed-winbash;當前 package 版本爲 0.1.7,許可證 MIT。DSH 要求 >=0.1.5-rc.3,Node.js 要求 >=20,運行環境還需已安裝 Git for Windows(提供 Git Bash)。

爲什麼 Windows 上默認沒有 bash

README 在 Windows 11 + dsh 0.1.5-rc.1 的沙箱內做過實測,常見嘗試均失敗:

嘗試 結果
bash -c(PATH 解析到 C:\Windows\System32\bash.exe) Bash/Service/CreateInstance/E_ACCESSDENIED
wsl.exe -e bash -c Wsl/Service/CreateInstance/E_ACCESSDENIED
C:\Program Files\Git\usr\bin\bash.exe -c fatal error - couldn't create signal pipe, Win32 error 5

因此本插件的前提就是:MSYS 無法在 ACL 受限 token 下正常啓動,需要在文件沙箱外 spawn Git Bash。工具描述中會寫明這一點,且不提供 sandbox_permissions 升級面。

核心功能

winbash 工具

  • 以 bash -c 執行命令,返回 stdout、stderr 與退出碼;非零退出按結果上報,不作爲工具層錯誤。
  • Git Bash 自動發現:優先 usr\bin\bash.exe(真實 MSYS2),再查 bin\bash.exe 包裝器;也可通過配置項 bashPath 顯式指定路徑。
  • PATH 修復:將 Git 的 usr\bin、mingw64\bin、cmd 前置。否則在僅含 Git\cmd 的典型 Windows PATH 下,ls、grep、sed、awk、find、sleep、wc 等會 command not found。
  • 有界輸出:保留 maxOutputBytes 窗口,超出部分寫入 spill 文件並在結果裏給出路徑;多字節邊界不會被截斷成亂碼。
  • 環境擦除:複用 @deepseek-ai/dsh-subprocess 的 scrubbedParentEnv,只轉發 dshEnv 與 Git 需要的變量;匹配 *KEY*、*TOKEN*、*SECRET*、*PASSWORD* 的憑證類環境變量不傳給子進程。
  • 超時與中斷:timeoutMs / maxTimeoutMs 到期或調用被中止時,對進程樹執行 taskkill /T /F;在 exit 上結算,並用 drainMs 有界排空 stdio。
  • 後臺任務:支持 run_in_background,走宿主的 ctx.jobs 註冊表,可增量讀取輸出。
  • 實現上命令內部一律顯式調用 Git Bash,不用裸 bash——在 Windows 上裸 bash 可能解析到 WSL shim。

與其他平臺的關係

非 win32 平臺不需要本插件:dsh-tool-bash 與 dsh-bash-sandbox 在其他平臺上默認啓用。

安裝與啓用

包內聲明瞭 dsh.bundle,bundle 補丁會自行掛載工具行,無需手工改 cordis.patch.yml。安裝後需重啓 DSH Web 生效。

# 從 npm 安裝並註冊到 web profile(推薦)
dsh plugin --profile web add dsh-unsandboxed-winbash

# 僅下載 npm package
npm install dsh-unsandboxed-winbash

# 或從 GitHub 安裝
dsh plugin --profile web add github:xswt442-cmd/dsh-unsandboxed-winbash

若僅安裝 npm 包而未通過 dsh plugin 註冊,需自行按 DSH 插件文檔完成掛載;推薦路徑是使用上面的 dsh plugin --profile web add 命令。

配置

可在 Cordis 補丁中插入 tool-winbash 節點,例如:

- insert:
    - id: tool-winbash
      name: dsh-unsandboxed-winbash/tool
      config:
        bashPath: ''          # 顯式指定 Git Bash 路徑(默認自動發現)
        gitPathPrefix: true   # 把 Git 的 usr\bin / mingw64\bin / cmd 前置到 PATH
        extraPath: ''         # 額外 PATH 前綴,';' 分隔(排在最前)
        drainMs: 250          # 子進程退出後等待輸出排空的上限
        timeoutMs: 120000     # 命令默認超時
        maxTimeoutMs: 600000
        maxOutputBytes: 64000
        maxSpillBytes: 67108864
        enableRunInBackground: true

Git Bash 自動發現順序爲:%ProgramFiles%\Git\usr\bin\bash.exe → %ProgramFiles%\Git\bin\bash.exe → %LOCALAPPDATA%\Programs\Git\usr\bin\bash.exe → %ProgramFiles(x86)%\Git\...。找不到且未配置 bashPath 時,只在調用 winbash 時報錯,插件掛載本身不會失敗。

典型用法

安裝並重啓 DSH Web 後,智能體會話裏會出現 winbash 工具。模型或工作流通過該工具傳入要在 Git Bash 中執行的 shell 片段(等價於 bash -c "..."),即可使用 MSYS 下的常見 Unix 命令,前提是本機已安裝 Git for Windows 且路徑可被自動發現或已在 bashPath 中指定。

需要受限、可審計的文件讀寫或修改時,仍應使用 DSH 的 fs 工具,而不是指望 winbash 遵守文件沙箱策略。

適用場景與注意

適合誰: 在 Windows 上跑 DSH Web 或同類 profile、希望智能體能執行 grep/sed/管道腳本等 Git Bash 能力、且接受「shell 命令在沙箱外、與 dsh 進程同權限」的開發者或運維場景。

安全與邊界(務必閱讀):

  • 命令在文件沙箱之外執行;pwsh、權限預設、/permission 與 fs 仍受各自沙箱與審批策略約束。
  • 插件以當前 dsh 進程權限運行;安裝前應閱讀 GitHub 倉庫 源碼與 MIT 許可證,確認符合你的安全策略。
  • 超時或被中止時會終止整棵進程樹;後臺任務在宿主退出時同步清理。

DSH 生態強調「一切皆插件」;SkillHub 目錄頁 是社區收錄站點,與 DeepSeek / 幻方無官方從屬關係。

鏈接

  • 目錄頁:https://www.skillhub.cn/plugins/xswt442-cmd/dsh-unsandboxed-winbash
  • GitHub:https://github.com/xswt442-cmd/dsh-unsandboxed-winbash
  • npm:https://www.npmjs.com/package/dsh-unsandboxed-winbash

經過上面的步驟,在 Windows 上即可在保持 fs 等沙箱能力不變的前提下,爲 DSH 補上可用的 Git Bash 工具鏈;是否啓用取決於你對沙箱外 shell 的接受程度與本機 Git 安裝情況。

羽毛球分组比赛记分
小程序二维码

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

小夜