Windows: AppContainer sandbox breaks when git on PATH is a shim (Scoop) #92

Open
opened 2026-11-18 12:48:58 +00:00 by Jer9 · 1 comment
Contributor

Symptom

On a Windows 11 tester machine with Git installed via Scoop, scripts/dev_packs.py base fails inside the AppContainer sandbox when invoking git:

  File "Y:\longshot\scripts\dev_packs.py", line 482, in cmd_base
    dirty = [p for p in changed_files(tree, "HEAD") if route([p], tree)]
  File "Y:\longshot\scripts\dev_packs.py", line 167, in changed_files
    return set(git(tree, "diff", "--name-only", commit).split("\n") + git(tree, "ls-files", "--others", "--exclude-standard").split("\n")) - {""}
  File "Y:\longshot\scripts\dev_packs.py", line 162, in git
    return subprocess.run(["git", "-C", tree] + list(args), check=True, capture_output=True, text=True).stdout.strip()
subprocess.CalledProcessError: Command '['git', '-C', 'Y:\\longshot', 'diff', '--name-only', 'HEAD']' returned non-zero exit status 1.

Root cause (and why #62's MinGit fallback doesn't trigger)

  1. With Scoop, git on PATH resolves to C:\Users\<user>\scoop\shims\git.exe, paired with git.shim:
    path = "C:\Users\<user>\scoop\apps\git\current\cmd\git.exe"
    
  2. Workspace.EnsureGitAsync (agent/Core/Workspace.cs, added in #62) only downloads MinGit when MinGit.OnPath(PATH) returns null. Because MinGit.OnPath (agent/Core/MinGit.cs) only checks File.Exists(Path.Combine(dir, "git.exe")), it sees C:\Users\<user>\scoop\shims\git.exe, returns non-null, and skips MinGit.
  3. WinHost.Git() (agent/Core/WindowsSandbox.cs) also stops at the first git.exe on PATH (C:\Users\<user>\scoop\shims\git.exe), only strips \cmd or \bin (not \shims), grants the AppContainer read/execute access only to C:\Users\<user>\scoop\shims, and puts C:\Users\<user>\scoop\shims on the sandbox PATH.
  4. Inside the AppContainer, Scoop's git.exe shim tries to launch C:\Users\<user>\scoop\apps\git\current\cmd\git.exe (which is outside the granted folders), fails, and exits with status 1. (safe.directory is already handled by WinEnv via GIT_CONFIG_COUNT=1.)

The same failure pattern applies to any package-manager shim on PATH whose target binary lives outside the shim directory (such as Scoop .shim stubs or Chocolatey shims).

Proposed fix & scope

  1. Skip shims when locating a sandbox-usable git.exe on PATH (agent/Core/MinGit.cs, agent/Core/WindowsSandbox.cs):
    • Share/align PATH lookup between MinGit.OnPath and WinHost.Git() so shim executables are skipped (e.g., when a sibling git.shim exists for Scoop, or a shim directory/stub such as Chocolatey's chocolatey\bin).
    • Continue scanning PATH so a real git.exe later on PATH (such as C:\Program Files\Git\cmd\git.exe) is still used if present.
    • If no non-shim git.exe exists on PATH, return null from OnPath so Workspace.EnsureGitAsync fetches and uses Beanstalk's own MinGit (<data>\mingit\cmd\git.exe), which runs off the Y: work drive inside the AppContainer. (Falling back to MinGit avoids NTFS junction issues with Scoop's current link and %USERPROFILE% traversal issues that granting scoop\apps\git directly would risk.)
  2. Unit tests (agent/tests/agent_core/SetupChecks.cs):
    • Cover skipping a directory containing a Scoop git.shim (both falling back to a later PATH entry and returning null to trigger MinGit).
  3. Optional companion check (if desired in scope):
    • Run git --version inside the Windows sandbox self-test (WinSandbox) so an unusable git.exe on PATH fails visibly at Setup instead of mid-job inside dev_packs.py.

(Separate repo note: in Longshot's scripts/dev_packs.py, git() uses capture_output=True, so CalledProcessError currently hides stderr.)

Workaround

Uninstalling Scoop's git (scoop uninstall git) so Beanstalk falls back to MinGit, or installing standard Git for Windows into C:\Program Files\Git (with C:\Program Files\Git\cmd ahead of any shims), resolves the failure.

### Symptom On a Windows 11 tester machine with Git installed via Scoop, `scripts/dev_packs.py base` fails inside the AppContainer sandbox when invoking `git`: ```text File "Y:\longshot\scripts\dev_packs.py", line 482, in cmd_base dirty = [p for p in changed_files(tree, "HEAD") if route([p], tree)] File "Y:\longshot\scripts\dev_packs.py", line 167, in changed_files return set(git(tree, "diff", "--name-only", commit).split("\n") + git(tree, "ls-files", "--others", "--exclude-standard").split("\n")) - {""} File "Y:\longshot\scripts\dev_packs.py", line 162, in git return subprocess.run(["git", "-C", tree] + list(args), check=True, capture_output=True, text=True).stdout.strip() subprocess.CalledProcessError: Command '['git', '-C', 'Y:\\longshot', 'diff', '--name-only', 'HEAD']' returned non-zero exit status 1. ``` ### Root cause (and why #62's `MinGit` fallback doesn't trigger) 1. With Scoop, `git` on `PATH` resolves to `C:\Users\<user>\scoop\shims\git.exe`, paired with `git.shim`: ```ini path = "C:\Users\<user>\scoop\apps\git\current\cmd\git.exe" ``` 2. `Workspace.EnsureGitAsync` (`agent/Core/Workspace.cs`, added in #62) only downloads `MinGit` when `MinGit.OnPath(PATH)` returns `null`. Because `MinGit.OnPath` (`agent/Core/MinGit.cs`) only checks `File.Exists(Path.Combine(dir, "git.exe"))`, it sees `C:\Users\<user>\scoop\shims\git.exe`, returns non-null, and skips `MinGit`. 3. `WinHost.Git()` (`agent/Core/WindowsSandbox.cs`) also stops at the first `git.exe` on `PATH` (`C:\Users\<user>\scoop\shims\git.exe`), only strips `\cmd` or `\bin` (not `\shims`), grants the AppContainer read/execute access only to `C:\Users\<user>\scoop\shims`, and puts `C:\Users\<user>\scoop\shims` on the sandbox `PATH`. 4. Inside the AppContainer, Scoop's `git.exe` shim tries to launch `C:\Users\<user>\scoop\apps\git\current\cmd\git.exe` (which is outside the granted folders), fails, and exits with status `1`. (`safe.directory` is already handled by `WinEnv` via `GIT_CONFIG_COUNT=1`.) The same failure pattern applies to any package-manager shim on `PATH` whose target binary lives outside the shim directory (such as Scoop `.shim` stubs or Chocolatey shims). ### Proposed fix & scope 1. **Skip shims when locating a sandbox-usable `git.exe` on `PATH` (`agent/Core/MinGit.cs`, `agent/Core/WindowsSandbox.cs`):** - Share/align `PATH` lookup between `MinGit.OnPath` and `WinHost.Git()` so shim executables are skipped (e.g., when a sibling `git.shim` exists for Scoop, or a shim directory/stub such as Chocolatey's `chocolatey\bin`). - Continue scanning `PATH` so a real `git.exe` later on `PATH` (such as `C:\Program Files\Git\cmd\git.exe`) is still used if present. - If no non-shim `git.exe` exists on `PATH`, return `null` from `OnPath` so `Workspace.EnsureGitAsync` fetches and uses Beanstalk's own `MinGit` (`<data>\mingit\cmd\git.exe`), which runs off the `Y:` work drive inside the AppContainer. (Falling back to `MinGit` avoids NTFS junction issues with Scoop's `current` link and `%USERPROFILE%` traversal issues that granting `scoop\apps\git` directly would risk.) 2. **Unit tests (`agent/tests/agent_core/SetupChecks.cs`):** - Cover skipping a directory containing a Scoop `git.shim` (both falling back to a later `PATH` entry and returning `null` to trigger `MinGit`). 3. **Optional companion check (if desired in scope):** - Run `git --version` inside the Windows sandbox self-test (`WinSandbox`) so an unusable `git.exe` on `PATH` fails visibly at Setup instead of mid-job inside `dev_packs.py`. *(Separate repo note: in Longshot's `scripts/dev_packs.py`, `git()` uses `capture_output=True`, so `CalledProcessError` currently hides `stderr`.)* ### Workaround Uninstalling Scoop's `git` (`scoop uninstall git`) so Beanstalk falls back to `MinGit`, or installing standard Git for Windows into `C:\Program Files\Git` (with `C:\Program Files\Git\cmd` ahead of any shims), resolves the failure.
Member

Possibly related, for context:

  • PR #62 fix(agent): a Windows PC without Git gets the agent's own MinGit — Merged MinGit fallback; current issue covers shim detection that this did not handle
Possibly related, for context: - PR #62 fix(agent): a Windows PC without Git gets the agent's own MinGit — Merged MinGit fallback; current issue covers shim detection that this did not handle
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Beanstalk#92
No description provided.