Repository navigation
insbx on Windows: a writable root's grant is kept, so a run no longer walks the tree - #85
Merged
Merged
Conversation
… walks the tree Measured on this repository (17,752 objects): the sandbox itself starts in 0.1 s, but every run granted each writable root to a per-run SID and revoked it after, and NTFS writes an inherited ACE into every object beneath a folder: 2.3 s per walk. `insbx run -w <repo> -- cmd /c echo ok` took 4.7 s, and 14-20 s under network deny (5-7 walks: the run SID, the offline account, its read of the current folder, each granted and revoked). incode runs one `insbx run` per shell command, so every tool call paid it. Now each writable root has its own SID, from the SHA-256 of its path (S-1-5-21-1111111111-2222222222-4141414141-a-b-c-d, hashed by Windows' CNG, no new dependency). The first run on a folder grants it (one walk); the grant is kept, and later runs read the folder's own ACL to see it is there. As OpenAI Codex's Windows sandbox does (a capability SID per writable root). The offline account's ACEs on roots and on a current folder are kept too. After: the same `echo ok` takes 0.05 s (allow) and 0.1 s (deny); the first run on a folder still walks it once. What keeps it confined: - the command's token carries the run SID (its temp directory, still per run and revoked after) and the SIDs of THIS run's roots only; the helper refuses any SID not of those shapes. A kept grant on another folder names a SID the token does not hold. - a root grant that fails part-way is taken off again, so the next run walks and reports it instead of trusting a half-granted tree. - a root holding insbx's own state (%LOCALAPPDATA%\insbx) is refused. What it costs, documented: - under network deny, a folder an earlier run was given stays READABLE to the offline account in later runs (never writable); - a file moved into a root keeps its old ACL, so the command cannot write it (fails closed) until `insbx revoke <ROOT>`. New: `insbx grants` (kept folders, and whether each still carries its grant) and `insbx revoke <DIR>... | --all`. Found by the new tests: a SID sub-authority above u32::MAX (the first choice, 4343434343) is stored by Windows as 4294967295, so the ACE named a different SID from the token's; a test now checks every prefix part. Tests (Windows, real insbx-offline account): 81 unit, 24 escape, none skipped. New: a kept grant is made once then only read (a file moved in is not re-granted until revoke), a kept grant is writable only to runs naming the folder, revoke takes root and account ACEs back, a part-way failure is not trusted.
… moved-in files need icacls /reset CI's windows runner showed the moved-file signal proves nothing: a file moved into a root is not re-ACL'd by any walk (here too, once looked at), so it could not show whether the second lease walked. The lease now records the roots whose grant it had to make; the test asserts the first lease walks, the second does not, and the one after revoke walks again. Docs that said revoke + the next run reaches moved-in files are corrected: no grant does (nor did the per-run one); icacls <FILE> /reset does, and the test shows it.
blockmandev
force-pushed
the
perf/insbx-kept-grants
branch
from
November 13, 2026 15:45
4221eba to
443b243
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #84 (the rename). Merge #84 first; this one then retargets to
main.The problem (measured)
The sandbox itself starts in 0.1 s. But each run granted every writable root to a per-run SID and revoked it after, and NTFS writes an inherited ACE into every object under a folder: 2.3 s per walk on this repo (17,752 objects). A network-deny run walked 5–7 times (run SID, offline account, its read of the current folder, each granted and revoked). incode runs one
insbx runper shell command, so every tool call paid it.insbx run -w <repo> -- cmd /c echo ok-w(current folder read)The fix: kept grants, one SID per folder
As OpenAI Codex's Windows sandbox does (
windows-sandbox-rs/src/cap.rs: a capability SID per writable root, persisted):S-1-5-21-1111111111-2222222222-4141414141-a-b-c-d, Windows CNG, no new dependency).passes_down) and walk nothing.What keeps it confined
CreateRestrictedTokenon a restricted token intersects them.)%LOCALAPPDATA%\insbx) is refused.Costs (documented in README and module docs)
insbx revoke <ROOT>.New commands
insbx grants(kept folders, and whether each still carries its grant) andinsbx revoke <DIR>... | --all.Tests (Windows, real
insbx-offlineaccount, none skipped)fmt, clippy
-D warnings(workspace), sandbox crate 81 unit + 24 escape pass. New or changed:revoke_keptthe next lease re-grants it)insbx grants/insbx revokeremove root and account ACEs4343434343) did not: Windows stored it as4294967295, so the ACE named a different SID from the token's. The new tests caught it.