fix(agent): the Windows setup gives AppContainers back the NUL device, as Windows 11 24H2 does #131

Merged
HumanBean merged 1 commit from HumanBean/Beanstalk:fix/nul-for-appcontainers into main 2026-11-21 08:13:19 +00:00
Owner

The root cause of "git can't start in the sandbox: could not open '/dev/null' ... Permission denied".

On some Windows builds, the NUL device's permissions have no entry for ALL APPLICATION PACKAGES, so nothing in an AppContainer can open NUL. Windows 11 24H2 has one by default:

(A;;0x1201bf;;;AC)(A;;0x1201bf;;;S-1-15-2-2)

Git for Windows opens NUL at its very start. The compiler probes (clang -### -c nul), cmd >nul and Python's DEVNULL in Longshot's build would fail next. Affected PCs ran Windows 10 22H2 and some 26200/26300 builds. Since nightly-217, each of them fails one job and then stops taking jobs.

What changes

  • The grant (agent/Core/WindowsNul.cs):
    • It opens \\.\NUL for READ_CONTROL | WRITE_DAC and adds an allow entry with mask 0x1201bf for S-1-15-2-1 and S-1-15-2-2, only where one is missing. It changes no other entry, and running it twice changes nothing.
    • It goes through Windows' own PowerShell with the script inline (-EncodedCommand). The P/Invoke uses an in-memory dynamic assembly, so there is no Add-Type and no temp file.
  • Every boot (device permissions reset at boot): a task \Beanstalk\NUL access for AppContainers.
    • It runs as SYSTEM (S-1-5-18), on a boot trigger, and its action is %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe with the grant inline.
    • It never loads a file a non-admin can write. The agent lives in a user-writable folder, so it isn't involved.
    • It's registered from XML embedded in the elevated script, so no file sits between the agent and Task Scheduler.
    • The elevated scripts pin PSModulePath to Windows' own modules, so Register-ScheduledTask can't load a module from the user's Documents.
  • One UAC prompt:
    • setup-windows-user now does it as well;
    • the setup window has a new Fix the sandbox button;
    • setup offers it when the self-test finds the problem;
    • there are standalone setup-windows-nul and remove-windows-nul commands, and remove-windows-user removes the task too.
      The grant applies at once, so no reboot is needed.
  • Self-test: a new nul check runs in the AppContainer before git. When it fails, the AppContainer is ruled out, so no job fails on it. The window and the main screen say: "Windows on this PC doesn't let sandboxed programs open NUL (some Windows builds); set up the Windows sandbox (one UAC prompt) to fix it".
  • Docs: agent/README.md and docs/using.md say what it changes, why, and how to undo it (delete the task; the permission goes at the next boot).

Not verifiable here

Only a real affected Windows PC can show these:

  • that SetSecurityInfo on the NUL handle takes;
  • that the task registers and runs at boot;
  • that the AppContainer then opens NUL and git gets past it. Git's current-folder lookup (\Device\MountPointManager) could be the next block, and the self-test would say so.

The first check is on a maintainer's affected PC after the next nightly.

Tests

The agent's checks on a throwaway container: 2354 passed. New NulChecks cover:

  • the DACL decision on SDDL (24H2's already has the entries: nothing added; one without them: both added, nothing else touched);
  • the task XML (SYSTEM, a boot trigger, the action under System32, no user-writable path);
  • the embedded command decoding to the grant;
  • the command-line lengths under 32,767;
  • the pinned module path;
  • the wording.

🤖 Generated with Claude Code

The root cause of "git can't start in the sandbox: could not open '/dev/null' ... Permission denied". On some Windows builds, the NUL device's permissions have no entry for ALL APPLICATION PACKAGES, so nothing in an AppContainer can open NUL. Windows 11 24H2 has one by default: `(A;;0x1201bf;;;AC)(A;;0x1201bf;;;S-1-15-2-2)` Git for Windows opens NUL at its very start. The compiler probes (`clang -### -c nul`), `cmd >nul` and Python's `DEVNULL` in Longshot's build would fail next. Affected PCs ran Windows 10 22H2 and some 26200/26300 builds. Since nightly-217, each of them fails one job and then stops taking jobs. ## What changes - **The grant** (`agent/Core/WindowsNul.cs`): - It opens `\\.\NUL` for READ_CONTROL | WRITE_DAC and adds an allow entry with mask 0x1201bf for S-1-15-2-1 and S-1-15-2-2, only where one is missing. It changes no other entry, and running it twice changes nothing. - It goes through Windows' own PowerShell with the script inline (`-EncodedCommand`). The P/Invoke uses an in-memory dynamic assembly, so there is no `Add-Type` and no temp file. - **Every boot** (device permissions reset at boot): a task `\Beanstalk\NUL access for AppContainers`. - It runs as SYSTEM (S-1-5-18), on a boot trigger, and its action is `%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe` with the grant inline. - It never loads a file a non-admin can write. The agent lives in a user-writable folder, so it isn't involved. - It's registered from XML embedded in the elevated script, so no file sits between the agent and Task Scheduler. - The elevated scripts pin `PSModulePath` to Windows' own modules, so `Register-ScheduledTask` can't load a module from the user's Documents. - **One UAC prompt:** - `setup-windows-user` now does it as well; - the setup window has a new **Fix the sandbox** button; - `setup` offers it when the self-test finds the problem; - there are standalone `setup-windows-nul` and `remove-windows-nul` commands, and `remove-windows-user` removes the task too. The grant applies at once, so no reboot is needed. - **Self-test:** a new `nul` check runs in the AppContainer before git. When it fails, the AppContainer is ruled out, so no job fails on it. The window and the main screen say: "Windows on this PC doesn't let sandboxed programs open NUL (some Windows builds); set up the Windows sandbox (one UAC prompt) to fix it". - **Docs:** `agent/README.md` and `docs/using.md` say what it changes, why, and how to undo it (delete the task; the permission goes at the next boot). ## Not verifiable here Only a real affected Windows PC can show these: - that `SetSecurityInfo` on the NUL handle takes; - that the task registers and runs at boot; - that the AppContainer then opens NUL and git gets past it. Git's current-folder lookup (`\Device\MountPointManager`) could be the next block, and the self-test would say so. The first check is on a maintainer's affected PC after the next nightly. ## Tests The agent's checks on a throwaway container: 2354 passed. New `NulChecks` cover: - the DACL decision on SDDL (24H2's already has the entries: nothing added; one without them: both added, nothing else touched); - the task XML (SYSTEM, a boot trigger, the action under System32, no user-writable path); - the embedded command decoding to the grant; - the command-line lengths under 32,767; - the pinned module path; - the wording. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(agent): the Windows setup gives AppContainers back the NUL device, as Windows 11 24H2 does
Some checks failed
CI / Conventional Commit title (pull_request) Successful in 5s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
CI / Coordinator tests (pull_request) Failing after 1m22s
CI / Agent build and checks (pull_request) Successful in 45s
CI / Coordinator image (pull_request) Successful in 10s
8d6279561e
On some Windows builds \Device\Null's DACL has no entry for ALL APPLICATION
PACKAGES or ALL RESTRICTED APPLICATION PACKAGES, so no program in the
AppContainer can open NUL: Git for Windows dies at its first open of
/dev/null ("could not open '/dev/null' for reading and writing: Permission
denied", several farm PCs in Nov 2026), and the build's compiler probes, cmd's
>nul and Python's DEVNULL would follow. Windows 11 24H2 has both entries.

- WinNul: adds the two missing entries (read and write, 0x1201bf, as 24H2) and
  changes nothing else. A device's DACL is made again at each boot, so the
  setup also registers the task \Beanstalk\NUL access for AppContainers: SYSTEM,
  at every boot, Windows' own powershell.exe with the script inline
  (-EncodedCommand, P/Invoke through an in-memory assembly): it runs or loads
  no file a non-administrator can write. Registered from XML inside the
  script, so no file sits between the agent and Task Scheduler.
- One UAC prompt: setup-windows-nul (and the window's Fix the sandbox, and
  setup's offer when the self-test finds it); setup-windows-user does it too.
  remove-windows-nul and remove-windows-user remove the task.
- The self-test's new nul check (before git) fails the AppContainer like git's,
  so no job fails on it; the window and the main screen say "Windows on this PC
  doesn't let sandboxed programs open NUL (some Windows builds); set up the
  Windows sandbox (one UAC prompt) to fix it". The self-test runs again after
  the fix, so the AppContainer is used at once.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member

Possibly related, for context:

  • issue #111 Two Windows testers fail every job before building, with the sandbox unable to read the job's working directory — Windows AppContainer failures stopping testers' jobs; distinct working-directory symptom
  • PR #125 fix: the farm pauses a PC that fails setup again and again, and Windows tests its sandbox again once it has git — Merged PR addressed same NUL failure with self-test/farm pause; this adds persistent permission repair
Possibly related, for context: - issue #111 Two Windows testers fail every job before building, with the sandbox unable to read the job's working directory — Windows AppContainer failures stopping testers' jobs; distinct working-directory symptom - PR #125 fix: the farm pauses a PC that fails setup again and again, and Windows tests its sandbox again once it has git — Merged PR addressed same NUL failure with self-test/farm pause; this adds persistent permission repair
HumanBean changed title from WIP: fix(agent): the Windows setup gives AppContainers back the NUL device, as Windows 11 24H2 does to fix(agent): the Windows setup gives AppContainers back the NUL device, as Windows 11 24H2 does 2026-11-21 08:13:16 +00:00
HumanBean deleted branch fix/nul-for-appcontainers 2026-11-21 08:13:19 +00:00
Sign in to join this conversation.
No reviewers
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!131
No description provided.