Repository navigation
sbx: network deny natively on Windows (layer 2) — offline account + WFP - #27
Merged
Merged
Conversation
…FP cuts off The way OpenAI Codex's Windows sandbox does it (codex-rs/windows-sandbox-rs: sandbox_users.rs, firewall.rs, wfp.rs, dpapi.rs, runner_client.rs). `sbx setup-windows` (elevated; refuses clearly without it; idempotent): - creates the local account sbx-offline (Users, never Administrators), random 256-bit password never shown, hidden from the sign-in screen; - stores the password DPAPI machine-scope in %ProgramData%\sbx\offline.conf under a protected ACL: SYSTEM, Administrators, the installing user; - adds persistent WFP filters (FwpmFilterAdd0, one transaction, fixed keys) on FWPM_CONDITION_ALE_USER_ID: connect, accept and raw ICMP blocked, v4 and v6, loopback included; one higher-weight permit for TCP to 127.0.0.1 on a fixed proxy port range (47600-47615, --proxy-ports); - --read <DIR> grants the account read on a toolchain; --remove undoes all. At run time, deny/proxy start a second helper as the account with CreateProcessWithLogonW (no profile), which builds the write-restricted token from its own token and starts the command; the first helper's job holds both. Roots are granted to the run SID and to the account (whose shared ACE is only revoked when no other live run needs it); the current folder and the helper program are granted for reading. The proxy listens in the permitted range. enforcement() reports deny/proxy enforced when the setup is found (record readable, account SID matches, filter present), else NotEnforced naming `sbx setup-windows`; auto then runs natively. `sbx doctor` reports it. Tests: pure parts unit-tested everywhere (record format, password, SDDL, filter specs, setup args, status, shared-ACE logic, spec transport); tests/escape_windows.rs gains gated network tests (TCP local/outside, UDP, writes and exit codes under deny, the account's grant, concurrent runs, proxy allowlist, mcp), SKIPPED without the setup. CI runs setup-windows on windows-latest before the sandbox tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
As the offline account, PowerShell started at C:\ instead of the run's folder, so relative paths (Set-Content started.txt) went to the drive root. Its FileSystem provider sets the first location by looking the current folder up in its parent (NormalizeRelativePath: Directory.EnumerateFiles / EnumerateDirectories(parent, leaf)), which needs FILE_LIST_DIRECTORY on the parent; the account has none on a folder under the user's profile, startup swallows the UnauthorizedAccessException and leaves the drive root. Each deny run now lets the account list the current folder's parent (unless it is a drive or share root, or a root or read folder of the run holds it): one allow ACE, FILE_LIST_DIRECTORY | FILE_TRAVERSE | FILE_READ_ATTRIBUTES | SYNCHRONIZE, no inheritance flags, written to that folder alone through its handle with SetKernelObjectSecurity (no propagation walk over the children). It is recorded in the grant record (`parent` lines; older records parse with none), kept while another live run lists the same folder, removed as that exact ACE only, and swept after a crash. An account grant on a folder that carries another run's listing ACE takes it off and puts it back, so SetEntriesInAclW cannot merge the inheritable grant into it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
The list ACE on the current folder's parent did not change it (CI: Get-Location still C:\). The test now prints what an explicit Set-Location to the current directory throws, and each folder's ACL up the chain, so the next run names the call that fails instead of a guess. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
CI showed the list ACE on the immediate parent was there and an explicit Set-Location to the current folder still failed "Access is denied": Windows PowerShell looks every component up in the folder above. The account now gets the same list-only, non-inherited ACE on each folder from the current folder's parent up to (not including) a drive or share root or the profiles folder (C:\Users, listable by every user already, and never re-ACLed by an elevated run), less what a root or read folder already holds. Bookkeeping, release and sweep are the existing per-folder ones. README says what the command can then see (names, no contents) on the way to the project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
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.
Closes #24 once CI proves it on real Windows. Draft until the Windows job is green with the gated network tests actually running.
Summary
Each design choice follows OpenAI Codex's
codex-rs/windows-sandbox-rs(HEAD d4e03acb); the file named is where it came from.Setup:
sbx setup-windows(elevated, idempotent;--removeundoes it)sbx-offline(NetUserAdd, assandbox_users.rsdoes).C:\Windows, and never in Administrators.hide_users.rs).dpapi.rs) in%ProgramData%\sbx\offline.conf.FwpmFilterAdd0, one transaction, fixed keys;wfp.rs) that match that account.127.0.0.1on ports 47600–47615 (--proxy-ports), soproxy(the host allowlist) works natively (firewall.rs).--read <dir>: grants the account read access to a toolchain outside system folders, such as~/.cargo.Running a command
CreateProcessWithLogonW, suspended, and assigns it to the job (runner_client.rs).CreateProcessWithLogonWcaps the command line at 1024 characters).Reporting
enforcement()marks deny and proxy as enforced only when the setup record is readable, the account's SID matches it and the main filter is present. Otherwise it says to runsbx setup-windowsas administrator.autopicks native with the setup and WSL without it.sbx doctorhas a new "offline user" line.Behaviour to know (in the crate README)
--read.\\host\sharepaths, which the kernel opens.proxyorallowfor those.CI
windows-latestrunssbx setup-windows(the runner is admin) andsbx doctorbeforecargo test -p incord-sandbox, so the gated tests run there.tests/escape_windows.rs:sbx mcp.Test plan
cargo clippy -p incord-sandbox --all-targets -D warnings,cargo test -p incord-sandbox, and the fullscripts/test-all.sh rust sbxcargo clippy -p incord-sandbox --target x86_64-pc-windows-gnu --all-targets -D warningsdoctorsays enforced, and the gated network tests run and pass. Things only real Windows can show:CreateProcessWithLogonWworks from the runner (inherited pipes, job assignment);curl.exerun without a profile;Generated by Claude Code