Repository navigation
Description
Why
Natively on Windows, every msys program (Git Bash, and anything linked against msys-2.0.dll) dies under sbx with CreateFileMapping ..., Win32 error 5 (documented as a known limit in the README and src/windows/mod.rs).
This blocks the main use case: Claude Code's Bash tool runs through Git Bash on Windows. sbx run ... -- claude starts the CLI (node isn't msys), but every Bash tool call fails. Today the only working path is SBX_BACKEND=wsl.
Cause (from msys2-runtime, winsup/cygwin/mm/shared.cc)
- Every msys process opens a per-user shared section named
<user SID>.<USER_VERSION>(user_info::create, name fromcygheap->user.get_windows_id). It holds per-user state, including the mount table. - It is created with
CreateFileMappingW(INVALID_HANDLE_VALUE, &sec_none, PAGE_READWRITE, ...).sec_nonehas no descriptor, so the section gets the default DACL of whichever process created it first. - The user's normal Git Bash usually creates it first: its DACL grants the user SID and SYSTEM, not the run's SID and not
Everyone. - The sandboxed bash has the same user SID, so it opens the same section by name and asks for write. The write-restricted token's restricted check needs one of its restricting SIDs (run SID,
Everyone, logon SID) granted write. None is, so: access denied, error 5. - The machine-wide
shared.<n>section is created withsec_all_nih(Everyone), so it passes. The per-user section is the culprit.
Do NOT fix it by granting the run SID on the existing section
That would make bash start, but the sandbox could then write the mount table the user's unsandboxed Git Bash reads (e.g. remap /usr/bin to a sandbox-writable folder, so the user's next normal bash runs planted binaries). That is a sandbox escape. The same leak exists in reverse whenever a sandboxed bash creates the section first and an unsandboxed one shares it. The sandbox must never share msys shared sections with processes outside the run.
Proposed fix: a private object namespace per run (BNO isolation)
Start the command with PROC_THREAD_ATTRIBUTE_BNO_ISOLATION, a per-run prefix (e.g. sbx-<rid>). The struct is PROC_THREAD_BNO_ISOLATION_ATTRIBUTE { BOOL IsolationEnabled; WCHAR IsolationPrefix[136]; }. If windows-sys 0.61 doesn't export the constant, it should be 0x00020013 (attribute number 19 | PROC_THREAD_ATTRIBUTE_INPUT); confirm against winbase.h.
Effect, if it behaves as expected:
- unprefixed and
Local\named objects of the command resolve into a private directory, so the first msys process in the run creates its own user section with the token's default DACL, which already includes the run SID (default_dacl_sddl), and the write succeeds; - the run never sees the user's real msys mount table or process table (
cygpid.*sections are opened through the sameopen_sharedpath), and two runs can't see each other's.
Where
crates/sandbox/src/windows/helper.rs, start(): the command is spawned with CreateProcessAsUserW / CreateProcessW and a plain STARTUPINFOW. Switch to STARTUPINFOEXW + EXTENDED_STARTUPINFO_PRESENT and an attribute list (InitializeProcThreadAttributeList / UpdateProcThreadAttribute) holding the BNO attribute. Keep CREATE_SUSPENDED and the job-object assignment as they are. The offline-account path already reaches this same call in the second helper, so CreateProcessWithLogonW not taking attribute lists doesn't matter.
Derive the prefix from the run's RID so it is unique per run and easy to recognise.
Must be measured before relying on it (not verified yet; nobody has run this)
- BNO isolation works for an unprivileged caller spawning under a write-restricted token (and under the offline account). If
CreateProcessAsUserWrejects the attribute, record the error and stop. - Children inherit it. The prefix is stored on the token (
TokenBnoIsolation), so it should, but bash spawninggit,sed, etc. must land in the same namespace. - msys also creates objects through absolute NT paths that isolation does not redirect:
\BaseNamedObjects\msys-...-<installation key>and\Sessions\BNOLINKS\<n>\msys-...-<installation key>(get_shared_parent_dir/get_session_parent_dir). Their directories are created with an Everyone descriptor, so they shouldn't fail, but list what lives in them during a run (WinObj orNtQueryDirectoryObject) and confirm nothing writable is shared with unsandboxed msys processes. If something is, report it here. - Pipes and ptys use named pipes (npfs), not BNO. Once the section is fixed they may be the next failure; capture any new error text.
Tests (tests/escape_windows.rs)
windows-latest runners have Git Bash at C:\Program Files\Git\bin\bash.exe.
- Starts: under
sbx run -w <tmp>,bash -c "echo ok > x && cat x"exits 0 and printsok. Run it once with an unsandboxedbashalready running (holding the user section open) to reproduce the real-world order. This test should fail with error 5 before the fix. - Still confined: under the same run,
bash -c "echo x > <outside root>"is refused. - Children:
bash -c "git --version && sed --version"works. - No shared state (the escape): start an unsandboxed bash, have a sandboxed bash add a user mount (
mount <tmp-as-windows-path> /sbx-probe; msys keeps user mounts in the per-user section), then confirm the unsandboxed bash'smountoutput is unchanged. - Under setup-windows: the same "starts" test with
--net deny.
Done when
- The tests above pass on
windows-latest. - README and the
src/windows/mod.rsdoc comment no longer list Git Bash as a known limit (or say exactly what still fails). sbx mcpon Windows can offersh/bashas an interpreter when Git Bash is present.
Generated by Claude Code
Activity
blockmandev commentedon Oct 22, 2026
Measured on Windows 11 (Git for Windows,
msys-2.0.dlldated 2025-10-28): BNO isolation works, but it does not fix Git Bash.1. Reproduced
With an unsandboxed Git Bash running (it holds the user section open):
2. BNO isolation, as proposed
helper::startusedSTARTUPINFOEXWwith one attribute,PROC_THREAD_ATTRIBUTE_BNO_ISOLATION, under the confining token.n | 0x20000encoding asPARENT_PROCESS(0x20000) andHANDLE_LIST(0x20002), giving0x20013.sbx-<rid>.CreateProcessAsUserWaccepts it for an unprivileged caller with a write-restricted token.3. It takes effect: a control
I held a
Local\sbx-bno-probe-…mutex outside and asked for it from inside a run (Mutex.TryOpenExisting):Truesbx runwithout the changeTruesbx runwith the changeFalseSo the attribute is applied, and Win32 named objects are isolated per run.
4. Git Bash still dies the same way
It's the same error:
CreateFileMapping <SID>.1, Win32 error 5.5. Why
Local\/Global\prefixes, which are what BNO isolation redirects.msys-2.0.dllholds the UTF-16 strings\BaseNamedObjects,\Sessions\andBNOLINKS, and noLocal\orGlobal\at all. My search was checked againstkernel32.dll, which it does find.get_shared_parent_dir/get_session_parent_dir). That is the case point 3 of this issue warned about. Isolation doesn't redirect these paths, so the per-user<SID>.1section is still the user's, and the restricted write check still refuses it.What this leaves
I stopped after these two measured attempts rather than guessing further. These are the candidate directions, none tried yet:
msys-<key>in those directory names, comes from wheremsys-2.0.dlllives. A copy of Git'susr\binruntime in an sbx-owned folder would get its own key and its own sections, never shared with the user's bash. This costs disk and an update story.AppContainerNamedObjects, but absolute\BaseNamedObjectspaths would need checking the same way, and AppContainer changes far more than objects.SBX_BACKEND=wslfor msys programs on Windows, as documented today.BNO isolation on its own is still a hardening worth weighing: a confined command can't open the user's
Local\mutexes, events or sections. But it changes what every Windows run can see (for example, a jobserver semaphore handed in from outside), so I haven't proposed it without that decision. The working code is kept locally, not pushed:D:/Projects/_backups/incord-code/sbx-bno-isolation-experiment-2026-10-22.patch.blockmandev commentedon Oct 22, 2026
Second round: the private-runtime idea measured, and the real blocker found in msys's source.
1. A private msys runtime gets past the shared section
I copied Git's
usr\bin(88 MB) to a scratch folder and ran itsbash.exeundersbx runwhile an ordinary Git Bash was running:CreateFileMapping <SID>.1, Win32 error 5(as before)couldn't create signal pipe, Win32 error 5So the installation key does separate the sections. But that was only the first wall.
2. Named pipes in general are fine
Under the same
sbx run, PowerShell creates a named pipe (NamedPipeServerStream) without trouble. The failure is specific to msys.3. The cause, in msys2-runtime (
msys2-3.6.11)sigproc.cc:527: the signal pipe is created withsec_user_nih(…, cygheap->user.sid()).sec/helper.cc:547-590(sec_acl): that DACL grantsGENERIC_ALLto the user's SID (plus the saved original SID) and Administrators. It adds no Everyone, no logon SID, nothing else.fhandler/pipe.cc:1149: the write end is then opened withGENERIC_WRITEagainst that DACL.A write-restricted token passes a write check only if a restricting SID (the run SID, Everyone, the logon SID) is also granted. None is, so msys refuses itself. Every msys object built through
sec_userhas this property, whatever its name. Name isolation (BNO, a private runtime) cannot fix it on its own.Directions this leaves
sbx-offlineaccount, with the account's own SID added to the restricting SIDs.BUILTIN\Users(ProgramData and the like) stay closed, because the account SID itself isn't granted there.<sbx-offline SID>.1, never yours.sbx setup-windows(admin, once), the same step insbx: a ready-made policy for running Claude Code (and what the Windows offline account must read) #40 needs. Two simultaneous runs share the account, so each could write what the other was granted while both run.sbx-offline. msys works, but confinement falls back to what the account can write,BUILTIN\Userslocations included. Weaker than (1); not recommended.sec_acl. That would fix it for every sandbox, but it is in someone else's hands and on their timeline.sec_aclgrants neither.SBX_BACKEND=wsl, as today.blockmandev commentedon Oct 24, 2026
Decided: run Git Bash as the
sbx-offlineaccount, with that account's SID added to the restricting SIDs. Only a policy that asks for it (msys = true) gets this, and such a run is exclusive: it waits until no other offline run is live, and blocks new ones while it runs.Why it must be exclusive: today two runs can't write each other's folders, pinned by
tests/escape_windows.rsconcurrent_deny_runs_share_a_root_and_cannot_write_each_others. That holds because only the per-run SID tells runs apart; the account's ACE is shared (windows/acl.rsLease::acquire,live_account_grants). Trusting the account SID during overlapping runs would break it.Limits of the design:
denyorproxy. Withallow, the command runs as your user, not the account (lib.rsSandbox::command).One risk to measure before shipping:
sbx-offline, and an owner can rewrite a file's permissions. Once the account SID is trusted, a Git Bash run might be able to change, and so reach, files that runs in other projects left behind.Blocked on:
sbx setup-windows, run once as admin. Nosbx-offlineaccount exists on this machine yet, so neither the fix nor that risk can be measured.blockmandev commentedon Oct 24, 2026
Unblocked: the owner ran \sbx setup-windows\ on this machine (sbx-offline account and 7 firewall filters created). \sbx check --net deny\ now reports network deny as enforced natively. Next, measured first and then built: the owner-rights risk on files the account owns, and Git Bash and Node child processes running as the account with its SID trusted (which also lifts the #68 limit).
[-]sbx on Windows: Git Bash / msys can't start natively (error 5); fix with a private object namespace per run[/-][+]insbx on Windows: Git Bash / msys can't start natively (error 5); fix with a private object namespace per run[/+]blockmandev commentedon Nov 13, 2026
Measured today (Windows 11,
insbx-offlineset up, Git for Windows bash), on a throwaway build that can add the token's own user SID to the restricting SIDs:--net deny -w .(runs asinsbx-offline)bash -c "echo ok > x && cat x", as todaycouldn't create signal pipe, Win32 error 5(as predicted above)ok,xwritten,whoami=insbx-offlinecmdwriting into another folder an earlier deny run was granted (a kept grant, since #85)Access is deniedThe account SID is what makes msys work, but since #85 keeps the offline account's grants, trusting that SID opens every folder any earlier network-deny run used.
Decided (owner): a separate account,
insbx-msys, used only for runs that need msys:insbx setup-windowscreates it, with its own firewall filters. This needs administrator, once.Building it now.
insbx --msys: probe thread/process locks as the command would, not as…