A local-first multi-agent app development platform, built on PenguinHarness
fix(plugins): sandbox-dsh 在 Windows 上拒绝 bash 并点名它要哪个 shell
lmlihengdcb77d0522fa
diff --git a/changelog/unreleased/2026-10-08-sandbox-dsh-windows-shell.md b/changelog/unreleased/2026-10-08-sandbox-dsh-windows-shell.mdnew file mode 100644index 00000000..d82631c6--- /dev/null+++ b/changelog/unreleased/2026-10-08-sandbox-dsh-windows-shell.md@@ -0,0 +1,33 @@+# The DSH backend on Windows refuses bash and names the shell it needs++- **Date:** 2026-10-08+- **Type:** fix+- **Scope:** `plugins`, `core`++[中文版](2026-10-08-sandbox-dsh-windows-shell.zh.md)++On Windows, the DSH backend's ACL restricted-token runner cannot start bash, and bash is the+harness's default session shell there (Git for Windows, or the MinGit the Windows package bundles).+Every confined command already failed closed, but with the runner's own error — which names WSL or an+MSYS internal rather than the setting that fixes it. Ported from upstream PenguinHarness (#972,+commit `c03e58c4`), which the fork did not carry.++- With a bash or sh session shell on Windows, the DSH backend now fails to load, with a reason naming+ the fix: `ADELIE_SHELL=pwsh`, or `ADELIE_SHELL=powershell` on a host without PowerShell 7, then+ restart the harness. The backend is reported unavailable with that reason, so the confining tier+ shows as unavailable instead of offering a tier that refuses every command. `sessionShell` is now+ exported from `@lmliheng/penguin-core/plugin` for this check; on a runtime whose core lacks it, the+ backend loads as before.+- A confined command whose program is bash or sh is still refused on Windows before the runner is+ involved. When the program is the session shell, the error names the same fix; when it is not (a+ stdio MCP Server launched through bash), the error says only that the runner cannot start an+ MSYS-runtime program, and does not mention `ADELIE_SHELL`.+- The failure is the MSYS runtime's, not bash's, so both checks cover every program on it: the other+ POSIX shells Git for Windows and MSYS2 ship (zsh, dash, `git-bash.exe`, …) and any program in their+ `usr\bin`. The backend's README states the measured matrix — both PowerShells run confined, bash and+ sh do not start.+- The default session shell is unchanged on every platform, and the backend's behavior on Linux and+ macOS is unchanged.+- A new test covers the load check and both refusals on every platform. On a Windows host it also+ checks that the default shell fails the load, and runs both PowerShells confined through the real+ runner.diff --git a/changelog/unreleased/2026-10-08-sandbox-dsh-windows-shell.zh.md b/changelog/unreleased/2026-10-08-sandbox-dsh-windows-shell.zh.mdnew file mode 100644index 00000000..aeb969af--- /dev/null+++ b/changelog/unreleased/2026-10-08-sandbox-dsh-windows-shell.zh.md@@ -0,0 +1,27 @@+# Windows 上的 sandbox-dsh 会拒绝 bash,并说明它需要哪种 shell++- **Date:** 2026-10-08+- **Type:** fix+- **Scope:** `plugins`, `core`++[English](2026-10-08-sandbox-dsh-windows-shell.md)++在 Windows 上,DSH 后端的 ACL restricted-token runner 起不了 bash,而 bash 正是本 harness 在 Windows+上的默认会话 shell(Git for Windows,或 Windows 包随附的 MinGit)。此前每一条受约束的命令本就按+fail-closed 失败,但报的是 runner 自己的错误 —— 提到的是 WSL 或 MSYS 内部细节,而不是能解决问题的那项+设置。本次从上游 PenguinHarness 移植(#972,提交 `c03e58c4`),此前本 fork 没有这一条。++- Windows 上会话 shell 是 bash 或 sh 时,DSH 后端现在加载即失败,原因写明解决办法:设+ `ADELIE_SHELL=pwsh`;主机没有 PowerShell 7 时设 `ADELIE_SHELL=powershell`;然后重启。该后端带着+ 这条原因被报为不可用,封禁档位显示为「不可用」,而不是可选、选中后每条命令被拒。为此+ `sessionShell` 现经 `@lmliheng/penguin-core/plugin` 导出;宿主的 core 没有这个导出时(较旧的+ 运行时),后端照常加载。+- 程序名是 bash 或 sh 的受约束命令,在 Windows 上仍在交给 runner 之前被拒:它就是会话 shell 时,错误+ 写的是同一条改法;不是会话 shell 时(以 bash 启动的 stdio MCP Server),错误只写明 runner 起不了+ MSYS 运行时的程序,不提 `ADELIE_SHELL`。+- 起不来的根源是 MSYS 运行时,而非 bash 本身,因此两项检查覆盖该运行时上的所有程序:Git for Windows+ 与 MSYS2 自带的其他 POSIX shell(zsh、dash、`git-bash.exe` 等),以及它们 `usr\bin` 下的任何程序。+ 该后端的 README 写明了实测矩阵:两种 PowerShell 能在约束下运行,bash 与 sh 起不来。+- 各平台上的默认会话 shell 不变;该后端在 Linux 与 macOS 上的行为也不变。+- 新增测试在所有平台上覆盖加载检查与两种拒绝;在 Windows 主机上还检查默认 shell 下加载即失败,并经+ 真实 runner 在约束下跑两种 PowerShell。diff --git a/packages/core/src/plugin/index.ts b/packages/core/src/plugin/index.tsindex dae29cb8..681ce84b 100644--- a/packages/core/src/plugin/index.ts+++ b/packages/core/src/plugin/index.ts@@ -3,10 +3,10 @@** Types, plus the five decorators — the same ones the harness's own modules are written* with (core kernel/decorators.ts: no imports, so a plugin's bundle carries them and- * nothing else of the SDK). The host that drives a plugin lives in whatever embeds this- * SDK (for the harness, `@lmliheng/penguin-server/plugin`); a plugin reaches THAT with- * `import type` only and stays a self-contained library that happens to satisfy an- * interface.+ * nothing else of the SDK) — and `sessionShell`, which a plugin reads from the host's copy+ * (see below). The host that drives a plugin lives in whatever embeds this SDK (for the+ * harness, `@lmliheng/penguin-server/plugin`); a plugin reaches THAT with `import type`+ * only and stays a self-contained library that happens to satisfy an interface.** A plugin is an npm package; what it carries is what it ships. Its MODULES — the same* unit the harness itself is built from — are written the same way: a `@Component` (or@@ -45,6 +45,15 @@ export { Bind, Component, Module, Provide, Use } from "../kernel/decorators.js";export type { Opaque, Slot } from "../kernel/markers.js";export { Interface } from "../kernel/markers.js";+/**+ * The harness's session shell — resolved once per process, the shell of the system prompt's+ * `Shell:` line — for a backend whose confinement depends on which program that is (DSH's+ * Windows ACL runner cannot start bash). Unlike the decorators it is the HOST's value: a+ * plugin that bundles this entry reads it from the host's copy at run time, by a specifier its+ * bundler leaves alone and by namespace, because a host core from before this export has none.+ */+export { sessionShell } from "../environment/tools/command/shell.js";+export type * from "./sandbox.js";/**diff --git a/plugins/sandbox-dsh/README.md b/plugins/sandbox-dsh/README.mdindex 15513bad..c7caa91a 100644--- a/plugins/sandbox-dsh/README.md+++ b/plugins/sandbox-dsh/README.md@@ -20,6 +20,40 @@ exactly `fs-write`. The sandbox service therefore never routes a `network` or`mask-paths` policy here, and the adaptor never has to silently drop a dimension itcannot honor — for those, use the bubblewrap, Seatbelt or WSL backend for your platform.+## Windows: run command sessions under PowerShell++The ACL restricted-token runner does not start bash, and bash is the harness's default+session shell on Windows (Git for Windows, or the MinGit the Windows package bundles). A bare+`bash` reaches System32's WSL launcher; an MSYS `bash.exe` or `sh.exe` aborts under the+restricted token. So with this backend confining commands on Windows, set the session shell+in the harness's environment and restart it:++| Shell | Under the ACL runner | Setting |+| --- | --- | --- |+| PowerShell 7 (`pwsh`) | runs confined | `ADELIE_SHELL=pwsh` |+| Windows PowerShell 5.1 | runs confined | `ADELIE_SHELL=powershell` — for hosts without PowerShell 7; it ships with Windows |+| bash / sh (Git for Windows, MinGit) | does not start | — |+| Any other MSYS-runtime program (zsh, dash, `git-bash.exe`, anything in an MSYS2 or Git for Windows `usr\bin`) | refused | — |++Measured on GitHub's `windows-latest` (Windows Server 2025, pwsh 7.6.6, Windows PowerShell+5.1.26100): a write inside the Workspace lands and a write outside it is denied. `cmd` also+starts under the runner; it is not measured beyond that. The abort comes from the MSYS runtime+(`msys-2.0.dll`) that Git for Windows and MSYS2 share, not from bash itself, so the backend+refuses the other POSIX shells those distributions ship and every program in their `usr\bin`+the same way.++Until the shell is set, the backend's load fails with a reason naming these settings, so it is+not mounted: the Session view lists `dsh-local` among the unavailable backends with that+reason, and the composer marks the confining tier unavailable instead of offering a tier whose+every command would be refused. A harness whose core does not report its session shell (an+older runtime) loads the backend as before.++Each confined command is still checked on its own. A bash, sh or other MSYS-runtime program is+refused before it reaches the runner: when it is the session shell, the error names the same+settings; when it is something else — a stdio MCP Server launched through bash, which+`ADELIE_SHELL` does not choose — the error says only that the runner cannot start an+MSYS-runtime program. Nothing here changes on Linux or macOS, where bash runs confined as usual.+## Requirements- The DSH dependencies (`@deepseek-ai/cordis`, `@deepseek-ai/dsh-sandbox`,diff --git a/plugins/sandbox-dsh/src/index.ts b/plugins/sandbox-dsh/src/index.tsindex 47b27892..2089512e 100644--- a/plugins/sandbox-dsh/src/index.ts+++ b/plugins/sandbox-dsh/src/index.ts@@ -29,8 +29,138 @@ import type {SandboxProviderSource,} from "@lmliheng/penguin-core/plugin";-/** Mount the stock DSH chain on a bare cordis Context — exactly how DSH's own tests mount it. */-export async function loadDshAdaptor(): Promise<SandboxProvider | null> {+/**+ * Programs the Windows ACL restricted-token runner cannot start — and they include the harness's+ * Windows default session shell (Git for Windows' bash, or the `sh.exe` of the MinGit the+ * Windows package bundles). Measured on windows-latest: a bare `bash`+ * reaches System32's WSL launcher before PATH ("Error code:+ * Bash/Service/CreateInstance/E_ACCESSDENIED"), and an MSYS bash or sh named by path aborts+ * under the write-restricted token ("fatal error - couldn't create signal pipe, Win32 error+ * 5" / "CreateFileMapping …, Win32 error 5"). In the same run both PowerShells ran confined,+ * writing inside the Workspace and denied outside it: pwsh 7.6.6 and Windows PowerShell 5.1.+ *+ * The abort is the MSYS runtime's (msys-2.0.dll, shared by Git for Windows and MSYS2), not+ * bash's, so it is refused by runtime: the POSIX shells those distributions ship, by name, and+ * any program in an MSYS `usr\bin` — the directory where every binary links that runtime.+ */+const MSYS_SHELLS = new Set(["bash", "sh", "zsh", "dash", "ksh", "mksh", "fish", "git-bash"]);++/** What the backend reads of the harness's session shell (core's `ShellInvocation`). */+export interface SessionShell {+ /** Executable name or path the harness spawns commands with. */+ command: string;+}++const unstartable = (program: string): boolean => {+ const segments = program.toLowerCase().split(/[\\/]+/);+ const base = (segments.at(-1) ?? "").replace(/\.exe$/i, "");+ return MSYS_SHELLS.has(base) || (segments.at(-3) === "usr" && segments.at(-2) === "bin");+};++/** The one setting that fixes an MSYS-runtime session shell, as every refusal of it words it. */+const SESSION_SHELL_FIX =+ "Set ADELIE_SHELL=pwsh (PowerShell 7) — or ADELIE_SHELL=powershell (Windows PowerShell " ++ "5.1) where PowerShell 7 is not installed — in the harness's environment and restart it";++/**+ * Fail this backend's load on Windows when the harness's session shell is one its ACL runner+ * cannot start. A backend whose load fails is not mounted: the sandbox service reports it with+ * this reason (the Session view's `unavailableBackends`), so the confining tier shows as+ * unavailable with the fix, rather than selectable and then refusing every command. `null` is+ * a host core that does not export the session shell (an older runtime): nothing is checked,+ * and `assertAclRunnerCanStart` still refuses per command.+ */+export function assertSessionShellConfinable(+ shell: SessionShell | null,+ platform: NodeJS.Platform = process.platform,+): void {+ if (platform !== "win32" || shell === null || !unstartable(shell.command)) return;+ throw new Error(+ `sandbox-dsh cannot confine commands on Windows under the session shell "${shell.command}": ` ++ "its ACL runner does not start bash, sh or any other MSYS-runtime program (Git for " ++ "Windows, the bundled MinGit, MSYS2). " ++ `${SESSION_SHELL_FIX}.`,+ );+}++/**+ * Refuse, before the runner is involved, a spawn whose program the ACL runner cannot start.+ * Without this every confined command still fails closed, but with the runner's error — which+ * names WSL or an MSYS internal, not the setting that fixes it. The same `confine()` carries a+ * stdio MCP Server's launch command, which `ADELIE_SHELL` does not choose: only a program that+ * IS the session shell is pointed at that setting. A `sessionShell` of `null` (a host core that+ * does not export it) cannot tell the two apart and keeps the session shell's wording.+ */+export function assertAclRunnerCanStart(+ argv: readonly string[],+ platform: NodeJS.Platform = process.platform,+ sessionShell: SessionShell | null = null,+): void {+ const program = argv[0];+ if (platform !== "win32" || program === undefined || !unstartable(program)) return;+ if (sessionShell === null || sessionShell.command.toLowerCase() === program.toLowerCase()) {+ throw new Error(+ `sandbox-dsh cannot confine "${program}" on Windows: its ACL runner does not start bash, ` ++ `sh or any other MSYS-runtime program (Git for Windows, the bundled MinGit, MSYS2). ` ++ `${SESSION_SHELL_FIX}; refusing to run the ` ++ "command unconfined.",+ );+ }+ throw new Error(+ `sandbox-dsh cannot confine "${program}" on Windows: its ACL runner does not start bash, ` ++ "sh or any other MSYS-runtime program (Git for Windows, the bundled MinGit, MSYS2, or " ++ "System32's WSL launcher); start the program " ++ "directly, or through PowerShell; refusing to run it unconfined.",+ );+}++/**+ * The host's plugin contract, named by a variable so this package's bundle leaves the import to+ * run time: tsup inlines `@lmliheng/penguin-core/plugin` for the decorators (a literal+ * specifier), and a second, bundled copy of the session shell would be this package's+ * resolution, not the harness's. Resolved where the plugin runs, from the installation; where+ * the host's core cannot be reached the import fails and `hostSessionShell` returns `null`.+ */+const HOST_CORE: string = "@lmliheng/penguin-core/plugin";++/**+ * The harness's session shell, from the host's core; `null` when that core does not export+ * `sessionShell` (it arrived after the runtimes a hot push may still be running on) or cannot+ * be reached. Read by namespace, never as a static named import: a missing export must not+ * fail this module's linking. `load` is injectable for tests.+ */+export async function hostSessionShell(+ load: () => Promise<unknown> = () => import(HOST_CORE),+): Promise<SessionShell | null> {+ let core: { sessionShell?: unknown };+ try {+ core = (await load()) as { sessionShell?: unknown };+ } catch {+ return null;+ }+ return typeof core.sessionShell === "function" ? (core.sessionShell() as SessionShell) : null;+}++/** What `loadDshAdaptor` reads of the running process; injectable for tests. */+export interface DshLoadHost {+ platform?: NodeJS.Platform;+ /** The session shell, `null` for a host core without one; read from the host when absent. */+ sessionShell?: SessionShell | null;+}++/**+ * Mount the stock DSH chain on a bare cordis Context — exactly how DSH's own tests mount it —+ * after checking, on Windows, that its ACL runner can start the session shell at all.+ */+export async function loadDshAdaptor(host: DshLoadHost = {}): Promise<SandboxProvider | null> {+ const platform = host.platform ?? process.platform;+ const shell =+ platform !== "win32"+ ? null+ : host.sessionShell !== undefined+ ? host.sessionShell+ : await hostSessionShell();+ assertSessionShellConfinable(shell, platform);const { Context } = await import("@deepseek-ai/cordis");const { LocalSandboxProvider } = await import("@deepseek-ai/dsh-sandbox-local");const ctx = new Context();@@ -46,6 +176,7 @@ export async function loadDshAdaptor(): Promise<SandboxProvider | null> {// full-access policy (which only ever arrives with a network/mask dimension it lacks).throw new Error("dsh-local does not implement full filesystem access with confinement");}+ assertAclRunnerCanStart(argv, platform, shell);const confined = dsh.confine(argv, {mode: policy.mode,workspaceRoot: policy.workspaceRoot,diff --git a/plugins/sandbox-dsh/test/windows-shells.test.ts b/plugins/sandbox-dsh/test/windows-shells.test.tsnew file mode 100644index 00000000..3d09c18c--- /dev/null+++ b/plugins/sandbox-dsh/test/windows-shells.test.ts@@ -0,0 +1,96 @@+// Which session shells the adaptor lets through to DSH's Windows ACL runner. Unit cases inject+// the platform and shell; the live half needs a Windows host whose runner is usable.+import { afterAll, describe, expect, it } from "vitest";+import { spawnSync } from "node:child_process";+import { existsSync, mkdtempSync, rmSync } from "node:fs";+import { homedir, tmpdir } from "node:os";+import path from "node:path";+import type { ConfinedArgv } from "@lmliheng/penguin-core/plugin";+import {+ assertAclRunnerCanStart as check,+ assertSessionShellConfinable,+ hostSessionShell,+ loadDshAdaptor,+} from "../src/index.js";++const REFUSED = /sandbox-dsh cannot confine .* ADELIE_SHELL=pwsh .* ADELIE_SHELL=powershell/;+const BASH = "C:\\Program Files\\Git\\usr\\bin\\BASH.EXE";++describe("the Windows session shell check", () => {+ // Any MSYS-runtime program aborts under the runner: its shells by name, anything in usr\bin.+ it.each(["bash", BASH, "dash.exe", "C:/msys64/usr/bin/env.exe"])("refuses %s", (program) =>+ expect(() => check([program], "win32")).toThrow(REFUSED),+ );++ it.each(["pwsh", "C:\\Program Files\\Git\\mingw64\\bin\\git.exe"])("passes %s", (program) =>+ expect(() => check([program], "win32")).not.toThrow(),+ );++ it("names ADELIE_SHELL only when the refused program is the session shell", () => {+ // An MCP Server's launch command goes through the same confine(); ADELIE_SHELL does not pick it.+ const mcp = () => check(["bash", "-c", "node s.js"], "win32", { command: "pwsh" });+ expect(mcp).toThrow(/does not start bash, sh or any other MSYS-runtime program/);+ expect(mcp).not.toThrow(/ADELIE_SHELL/);+ expect(() => check([BASH], "win32", { command: BASH })).toThrow(REFUSED);+ });++ it("fails the backend's load on Windows under an MSYS shell, before DSH loads", async () => {+ const load = loadDshAdaptor({ platform: "win32", sessionShell: { command: "sh" } });+ await expect(load).rejects.toThrow(REFUSED);+ });++ it("passes a PowerShell, any shell off Windows, and a host core without the export", () => {+ expect(() => assertSessionShellConfinable({ command: "pwsh" }, "win32")).not.toThrow();+ expect(() => assertSessionShellConfinable({ command: "bash" }, "linux")).not.toThrow();+ expect(() => check(["bash"], "linux")).not.toThrow();+ expect(() => assertSessionShellConfinable(null, "win32")).not.toThrow();+ });++ it("reads the session shell from the host core, null when it has none", async () => {+ const shell = { command: "sh" };+ expect(await hostSessionShell(async () => ({ sessionShell: () => shell }))).toEqual(shell);+ expect(await hostSessionShell(async () => ({}))).toBeNull();+ expect(await hostSessionShell(() => Promise.reject(new Error("no package")))).toBeNull();+ expect(typeof (await hostSessionShell())?.command).toBe("string");+ });+});++const ws = mkdtempSync(path.join(tmpdir(), "adelie-dsh-shells-"));+afterAll(() => rmSync(ws, { recursive: true, force: true }));+// Loaded as on a host core without the session shell, so the suite reaches the per-command check.+const provider =+ process.platform === "win32"+ ? await loadDshAdaptor({ sessionShell: null }).catch(() => null)+ : null;+const confine = (argv: string[]): ConfinedArgv =>+ provider!.confine(argv, { mode: "workspace-write", workspaceRoot: ws });+const run = (c: ConfinedArgv, cwd = ws) =>+ spawnSync(c.argv[0]!, c.argv.slice(1), {+ cwd,+ env: { ...process.env, ...c.env },+ encoding: "utf8",+ timeout: 60_000,+ windowsHide: true,+ });+// The gate hands over an absolute program: it measures whether the runner confines at all.+const usable = await Promise.resolve(provider)+ .then((p) => p !== null && Boolean(confine([process.execPath])))+ .catch(() => false);++describe.skipIf(!usable)("the real ACL runner (Windows, host-gated)", () => {+ // What the refusal points at: both PowerShells write inside the Workspace and are denied outside.+ const pwsh = spawnSync("where", ["pwsh"], { windowsHide: true }).status === 0;+ it.each(["powershell", ...(pwsh ? ["pwsh"] : [])])("%s runs confined", (shell) => {+ const outside = path.join(homedir(), `adelie-dsh-shells-${shell}-${process.pid}.txt`);+ try {+ const body = `Set-Content -LiteralPath in-${shell}.txt -Value ok; try { Set-Content -LiteralPath '${outside}' -Value leak -ErrorAction Stop } catch { $_.Exception.Message }`;+ const r = run(confine([shell, "-NoLogo", "-NoProfile", "-Command", body]));+ expect(r.status).toBe(0);+ expect(existsSync(path.join(ws, `in-${shell}.txt`))).toBe(true);+ expect(existsSync(outside)).toBe(false);+ expect(r.stdout).toMatch(/access to the path .* is denied/i);+ } finally {+ rmSync(outside, { force: true });+ }+ });+});