Skip to content

sbx on Windows, layer 2: block the network natively (offline user + firewall) #24

Closed

Description

@blockmandev

Why

sbx's native Windows backend (layer 1) confines writes with a write-restricted token and per-run ACL grants, and applies job-object limits. All 15 escape tests passed on real Windows in CI (run on main after #16). But it cannot block the network. A policy with network = deny or proxy is refused natively, and auto forwards it to WSL.

Approach (the one OpenAI Codex's Windows sandbox takes)

  1. sbx setup-windows (elevated, idempotent; --remove undoes it):
    • creates a local sbx-offline user with a random password, stored protected under %ProgramData%\sbx;
    • adds firewall/WFP rules that block all outbound traffic for that user's SID.
  2. At run time, when the policy needs network deny and setup is present: start the command as that user, still under the write-restricted token, the per-run SID's ACL grants and job limits.
  3. Reporting: enforcement() reports network deny as Enforced when setup is present, otherwise "run sbx setup-windows as administrator". auto prefers native when setup is present. sbx doctor says which.
  4. Proxy: if the firewall/WFP can allow only loopback to the parent's proxy port, the host allowlist works natively too; otherwise it stays on WSL.
  5. CI: the windows-latest job runs sbx setup-windows (the runner is admin) before cargo test -p incord-sandbox. The gated escape tests then prove deny on real Windows.

Status: being built now. A PR will link here.

Where the code is

crates/sandbox/src/windows/{mod,token,acl,helper}.rs, src/backend.rs, src/main.rs (doctor), tests/escape_windows.rs, scripts/install-windows.ps1.

Verify locally (Windows, after the PR merges)

cargo build -p incord-sandbox --release
# elevated PowerShell:
target\release\sbx.exe setup-windows
# normal PowerShell:
target\release\sbx.exe doctor                     # network deny: enforced
target\release\sbx.exe run --net deny -w . -- powershell -c "Test-NetConnection example.com -Port 443"   # must fail
target\release\sbx.exe run -w . -- powershell -c "Test-NetConnection example.com -Port 443"              # succeeds
cargo test -p incord-sandbox --test escape_windows -- --test-threads=1
# undo: (elevated) target\release\sbx.exe setup-windows --remove

Done when

  • CI green on Windows with the gated network tests running, not skipped
  • sbx doctor reports network deny as enforced after setup
  • The setup user and its credential are unreadable from inside the sandbox
  • --remove leaves no user, rule or file behind

Generated by Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions