Fixes #881.
Every exec_command on a Windows machine that had run zero sandbox setup aborted with:
zero-windows-command-runner.exe: windows sandbox setup is out of date: permission roots or deny lists changedFile tools worked. Only shell execution died, and zero doctor reported sandbox.backend as [pass] throughout, so nothing pointed at the cause. @baoyu0 reported it with a trace that lands on the same two functions.
The bug
Setup fingerprinted the bare permission profile into the marker. Every command arrived with the per-workspace runtime root already appended by permissionProfileWithRuntime, so the plan the runner computed could never match the one setup stored. A marker written seconds earlier was rejected permanently.
Both sides now fold in the same runtime candidate set before the profile is fingerprinted.
Three things this has to get right
Each of these broke it once while I was building it, so they are worth stating.
Both candidates, not the one this process would pick. sandboxRuntimeRootFor prefers the cache-derived root and falls back to the temp-derived one when the cache sits inside the workspace, and that choice is per process. Granting only one left a command that fell back writing to a tree with no ACE on it.
The fallback has to be derived rather than minted. It used os.MkdirTemp memoized in a process-global map, so the answer was private to whichever process asked first: setup granted temp root A, the next command derived root B, teardown cleaned a third. It is now a hash of the workspace and creates nothing, so every process agrees without sharing state.
The runner cannot derive the candidates itself. It runs re-exec'd as zero __windows-command-runner with TEMP and TMP already pointed at the sandbox runtime temp, so os.TempDir() there returns the redirected value. The profile is augmented in the parent and passed down.
Why this is separate from #808
#808 carries this fix among the Windows principal work. That PR has open architectural questions from @jatmn, most notably the process-launch mechanism, and I did not want a user-visible outage on one platform waiting behind a design decision. Nothing here depends on the principal work.
If #808 lands first this becomes redundant and I will close it. If this lands first, #808 rebases onto it.
On the tests
The composition test (windows_setup_runtime_root_test.go) proves the pieces agree, but it calls WindowsSandboxProfileWithRuntimeRoots directly and stays green even with the production call site deleted. That is the same class of bug as the one being fixed, so it is not sufficient on its own.
windows_runner_marker_windows_test.go drives BuildCommandPlan and asserts the runtime roots reach the runner's argv. Reverting the call in windows_runner.go fails it and names the missing root:
the runner argv does not carry runtime root C:\...\Temp\zero\runtime\v1\6135cb3d;
setup grants it, so the plans disagree and every command dies on
"permission roots or deny lists changed"Validation
go build ./..., go vet ./..., gofmt clean, go test ./internal/sandbox/ green on Windows 11.
Summary by CodeRabbit
-
Bug Fixes
- Improved Windows sandbox compatibility by consistently identifying workspace, cache, and temporary runtime paths.
- Ensured required runtime directories are created with the correct writable permissions.
- Improved handling of symbolic links and unresolved path segments.
- Added clearer diagnostics when fallback runtime locations conflict with the workspace.
-
Reliability
- Runtime locations are now deterministic across processes and tied to the workspace.
- Improved consistency of sandbox permissions and command execution across environments.
Activity
496Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: f3a44b09b955
Changed files (9): internal/doctor/hardening.go, internal/sandbox/runtime_state.go, internal/sandbox/windows_runner.go, internal/sandbox/windows_runner_marker_windows_test.go, internal/sandbox/windows_setup.go, internal/sandbox/windows_setup_provision_test.go, internal/sandbox/windows_setup_runtime_root_test.go, internal/sandbox/windows_setup_windows.go, internal/sandbox/windows_unelevated.go
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: 9ddb01f0d4a9
Changed files (12): internal/doctor/hardening.go, internal/sandbox/runtime_physical_path.go, internal/sandbox/runtime_physical_path_windows.go, internal/sandbox/runtime_root_alias_test.go, internal/sandbox/runtime_state.go, internal/sandbox/windows_runner.go, internal/sandbox/windows_runner_marker_windows_test.go, internal/sandbox/windows_setup.go, internal/sandbox/windows_setup_provision_test.go, internal/sandbox/windows_setup_runtime_root_test.go, internal/sandbox/windows_setup_windows.go, internal/sandbox/windows_unelevated.go
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: 9b96ab9223fd
Changed files (12): internal/doctor/hardening.go, internal/sandbox/runtime_physical_path.go, internal/sandbox/runtime_physical_path_windows.go, internal/sandbox/runtime_root_alias_test.go, internal/sandbox/runtime_state.go, internal/sandbox/windows_runner.go, internal/sandbox/windows_runner_marker_windows_test.go, internal/sandbox/windows_setup.go, internal/sandbox/windows_setup_provision_test.go, internal/sandbox/windows_setup_runtime_root_test.go, internal/sandbox/windows_setup_windows.go, internal/sandbox/windows_unelevated.go
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: 9b96ab9223fd
Changed files (12): internal/doctor/hardening.go, internal/sandbox/runtime_physical_path.go, internal/sandbox/runtime_physical_path_windows.go, internal/sandbox/runtime_root_alias_test.go, internal/sandbox/runtime_state.go, internal/sandbox/windows_runner.go, internal/sandbox/windows_runner_marker_windows_test.go, internal/sandbox/windows_setup.go, internal/sandbox/windows_setup_provision_test.go, internal/sandbox/windows_setup_runtime_root_test.go, internal/sandbox/windows_setup_windows.go, internal/sandbox/windows_unelevated.go
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: 47f9553a64c1
Changed files (31): internal/doctor/hardening.go, internal/doctor/windows_runtime_stamp_test.go, internal/sandbox/runtime_physical_path.go, internal/sandbox/runtime_physical_path_windows.go, internal/sandbox/runtime_root_alias_test.go, internal/sandbox/runtime_root_guard.go, internal/sandbox/runtime_root_guard_helper_test.go, internal/sandbox/runtime_root_guard_link_unix_test.go, internal/sandbox/runtime_root_guard_link_windows_test.go, internal/sandbox/runtime_root_guard_test.go, internal/sandbox/runtime_root_guard_unix.go, internal/sandbox/runtime_root_guard_windows.go, and 19 more
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: e87439120324
Changed files (33): internal/doctor/hardening.go, internal/doctor/windows_runtime_stamp_test.go, internal/sandbox/runtime_physical_path.go, internal/sandbox/runtime_physical_path_windows.go, internal/sandbox/runtime_root_alias_test.go, internal/sandbox/runtime_root_guard.go, internal/sandbox/runtime_root_guard_helper_test.go, internal/sandbox/runtime_root_guard_link_unix_test.go, internal/sandbox/runtime_root_guard_link_windows_test.go, internal/sandbox/runtime_root_guard_test.go, internal/sandbox/runtime_root_guard_unix.go, internal/sandbox/runtime_root_guard_windows.go, and 21 more
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: dda671de6e3e
Changed files (34): internal/doctor/hardening.go, internal/doctor/windows_runtime_stamp_test.go, internal/sandbox/runtime_physical_path.go, internal/sandbox/runtime_physical_path_windows.go, internal/sandbox/runtime_root_alias_test.go, internal/sandbox/runtime_root_guard.go, internal/sandbox/runtime_root_guard_helper_test.go, internal/sandbox/runtime_root_guard_link_unix_test.go, internal/sandbox/runtime_root_guard_link_windows_test.go, internal/sandbox/runtime_root_guard_test.go, internal/sandbox/runtime_root_guard_unix.go, internal/sandbox/runtime_root_guard_windows.go, and 22 more
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Zero automated PR review
Verdict: No blockers found
Blockers
- None found.
Validation
- [pass] Diff hygiene:
git diff --check - [pass] Tests:
go test ./... - [pass] Build:
go run ./cmd/zero-release build - [pass] Smoke build:
go run ./cmd/zero-release smoke
Scope
Head: dda671de6e3e
Changed files (34): internal/doctor/hardening.go, internal/doctor/windows_runtime_stamp_test.go, internal/sandbox/runtime_physical_path.go, internal/sandbox/runtime_physical_path_windows.go, internal/sandbox/runtime_root_alias_test.go, internal/sandbox/runtime_root_guard.go, internal/sandbox/runtime_root_guard_helper_test.go, internal/sandbox/runtime_root_guard_link_unix_test.go, internal/sandbox/runtime_root_guard_link_windows_test.go, internal/sandbox/runtime_root_guard_test.go, internal/sandbox/runtime_root_guard_unix.go, internal/sandbox/runtime_root_guard_windows.go, and 22 more
This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.
Action performed
-
Comments resolved and changes approved.
@coderabbitai review
Action performed
-
Review finished.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
@coderabbitai approve
Action performed
-
Comments resolved and changes approved.
Went through the four commits @jatmn pushed here (d06baec9, 8a520e9f, 5f0e89c2, 1ed27230). All good, thank you:
BuildCommandPlanfails closed when the command's environment names a sandbox home that cannot be resolved, where it used to carry on with the ambient one;zero sandbox setupundoes its own preparation only when the helper could not have published a marker (it never started, or it exited with the new unpublished code 3), so a helper that published and then failed keeps its runtime tree;- inside the helper, every exit before the marker is written uses the unpublished code, and a failed lock release after a publish exits 1, so the caller leaves the published state alone.
On Windows internal/sandbox passes and the sandbox tests in internal/cli pass. Four reverts each fail a named test: rolling back on any helper error, never rolling back, ignoring the home resolution error, and reporting a published marker as unpublished.
Zero automated PR review
Verdict: No blockers found
Blockers
Validation
git diff --checkgo test ./...go run ./cmd/zero-release buildgo run ./cmd/zero-release smokeScope
Head:
f0dc3b3c3454Changed files (9):internal/doctor/hardening.go,internal/sandbox/runtime_state.go,internal/sandbox/windows_runner.go,internal/sandbox/windows_runner_marker_windows_test.go,internal/sandbox/windows_setup.go,internal/sandbox/windows_setup_provision_test.go,internal/sandbox/windows_setup_runtime_root_test.go,internal/sandbox/windows_setup_windows.go,internal/sandbox/windows_unelevated.goThis deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.