Repository navigation
Fix Sandbox "Access is denied" failures and keep the Sandbox window on screen - #964
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new ancestor-creation path has a race that can leave the coordination directory writable by another user.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Fixes Windows Sandbox bootstrap failures caused by restrictive inherited ACLs.
Changes:
- Preserves normal permissions on shared state ancestors.
- Grants SYSTEM access to Sandbox bootstrap folders.
- Improves
wsb sharediagnostics and regression coverage.
| File | Description |
|---|---|
InteractiveDesktopPaths.cs |
Avoids restricting missing ancestors. |
WsbHResult.cs |
Defines the access-denied HRESULT. |
WindowsSandboxCli.cs |
Adds share-specific failure reporting. |
WindowsSandboxBackend.cs |
Prepares bootstrap folder permissions. |
SandboxShareAccess.cs |
Implements SYSTEM ACL handling. |
WindowsSandboxCliTests.cs |
Tests share error guidance. |
SandboxUxRegressionTests.cs |
Tests locked state-root recovery. |
SandboxShareAccessTests.cs |
Tests ACL grant behavior. |
InteractiveDesktopPathsHardeningTests.cs |
Tests inherited ancestor permissions. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Build Metrics ReportValidation passed. All required build and validation jobs succeeded. Binary Sizes
.NET Test Results (TRX reports)Other suites are reflected in the overall validation status above. ✅ 8088 passed, 37 skipped out of 8125 tests in 1347.1s (+20 tests, +176.3s vs. baseline) Test Coverage✅ 86.5% line coverage, 81% branch coverage · ✅ no change vs. baseline CLI Startup Time63ms median (x64, Try This BuildInstalls the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing. & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 964Switching between builds often?Put the tool on your PATH once: & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPathThen this build is just: winapp-pr 964Run Updated 2026-10-08 00:14:00 UTC · commit |
--on sandbox failing with "Access is denied … restart the host"- #942's renamed ui help (UiHelpRenderer/UiUnknownCommand) is kept in this branch's shared CompactHelpRenderer/ UnknownGroupCommand, with #942's final changes ported (golden path outside the description, synonyms instead of aliases, control-character escaping, command list only without a suggestion). - Sandbox staging keeps this branch's content-named payload directories, which avoid #964's in-place replace; #964's test now checks an older held agent doesn't block this version. - Bulk descendant dedupe from this branch is kept on main's search structure. - C++ WinUI projects (.vcxproj with UseWinUI, or XAML items with the Windows App SDK) are classified as WinUI, so DevTools is on by default for them. Co-authored-by: Copilot App <[email protected]>

Description
This fixes three problems that made
--on sandboxlook broken while the Sandbox itself was healthy.1. Commands failed with "Access is denied … restart the host"
Every command that prepares the guest agent failed this way. Retrying didn't help, and restarting the host doesn't fix it either.
Root cause. The failing call is
wsb share(--jsonreports"wsbVerb": "share"). It isn't related to the guest's interactive session. When UI coordination ran first, it created%USERPROFILE%\.winapp\state\uiwithDirectoryInfo.Create(DirectorySecurity). That call also applies its protected, current-user-only permissions to every folder it has to create on the way, including the shared%USERPROFILE%\.winapp\stateroot. This shipped in v0.7.0. Every Sandbox bootstrap folder understate\targets\…then has no SYSTEM access. Windows Sandbox shares folders as SYSTEM, sowsb sharereturnsE_ACCESSDENIED. Genericwsbfailure handling then suggested restarting the host.Measured with plain
wsb shareon a live Sandbox:%TEMP%E_ACCESSDENIEDE_ACCESSDENIEDFix:
sandbox_transport_failedwith the folder that couldn't be shared and the HRESULT. For access denied, it names SYSTEM as the account that needs access and shows theicaclscommand that grants it. It never suggests restarting the host. The error table indocs/sandbox-execution.mdnow documentssandbox_transport_failed.2. The Sandbox window was hidden off-screen
winapp moved the Sandbox window it opens 32,000 pixels to the left of the desktop so it wouldn't steal focus. A running Sandbox therefore looked closed, and opening Windows Sandbox from Start then failed with Windows' "Only one running instance of Windows Sandbox is allowed", with no next step.
Fix:
uicommand needs the window and it's minimized, winapp restores it the same way, behind your window. This path was also broken: a minimized window can't be verified because its remote desktop drops out of the UI tree, soui hover --on sandboxfailed with "its remote desktop could not be verified" and left the window minimized. winapp now restores the window first and verifies it afterwards.docs/sandbox-execution.mdand thewinapp-sandboxskill now cover:wsb connectshows it again;Ending the Sandbox automatically when its window closes is split into a follow-up PR, stacked on this one.
3. Switching winapp builds with a Sandbox running crashed
If the Sandbox still held the previous build's agent binary, replacing it crashed the command with an unhandled
UnauthorizedAccessException. It now reportssandbox_agent_incompatibleand says to stop the Sandbox withwsb stop --id <id>(closing its window doesn't stop it), then retry.Usage Example
All on an ARM64 host. "Before" is
winapp 0.7.1-nmetulev-devtools.51or this PR's base; "after" is this branch's NativeAOT build.Access denied. Before:
After, on a brand-new Sandbox, with
%USERPROFILE%\.winapp\statestill locked to the current user the way v0.7.0 leaves it:Minimized Sandbox window. Before:
After:
The window was restored on screen, directly behind the active window, without taking focus.
Switching builds. Before (exit 1):
After (exit 70). The live run used earlier wording; this is the current message, as asserted by the regression test:
Related Issue
None.
Type of Change
Checklist
plugins/winapp/skills/(if CLI commands/workflows changed)Screenshots / Demo
N/A. This is CLI-only; see the before/after output above.
Additional Notes
Tests added. Each regression test fails without its production change and passes with it.
SandboxShareAccessTestsandCenterInWorkArea_…are unit tests for new helpers.SandboxUxRegressionTests.BootstrapShares_UnderACurrentUserOnlyStateRoot_GrantSystemdrives the real backend with a state root locked to the current user, and checks that every folder passed towsb sharegrants SYSTEM.InteractiveDesktopPathsHardeningTests.MissingAncestorsAreNotRestricted: the coordination folder is current-user-only, and the parent it creates still inherits.WindowsSandboxCliTests.Share_AccessDenied_NamesTheFolderAndNeverSuggestsRestartingTheHostandShare_OtherFailure_NeverSuggestsRestartingTheHostuse the exactwsbstderr and exit code observed live.SandboxShareAccessTests: the SYSTEM grant helper grants when missing, is idempotent, keeps the user's access, and ignores inherit-only grants.WindowsSandboxWindowControllerTests):EnsureClientReady_MinimizedClient_IsRestoredBeforeItIsVerifiedEnsureClientReady_MinimizedClientWinappDidNotRecord_IsRestoredEnsureClientReady_MinimizedClientBesideAnUnverifiedWindow_IsNotMovedEnsureClientReady_ClientOnNoMonitor_IsBroughtBackCenterInWorkArea_PlacesTheClientInsideTheWorkAreaSandboxUxRegressionTests.StagedAgentFromAnotherVersion_ThatCannotBeReplaced_IsAVersionConflict.Checked live with this code, on fresh Sandboxes:
target execsucceeded in 21–26 sui hoverui hovertarget screenshotwhile the window is coveredTried and dropped: reconnecting a closed window up front. I tried reconnecting before starting the agent whenever no Sandbox window process was running, to skip one failed agent start. Measured with the window closed and the guest agent restarted, it made recovery slower. Sandboxes of different ages differ in overall speed, so compare within a row:
A process timeline showed why: reconnecting first slowed the guest's SYSTEM firewall step to 16 s. The existing order is kept, and a code comment records the measurement.
Local validation. On ARM64 Windows with Windows Sandbox:
Sandbox,InteractiveDesktop,ExecutionTarget,TargetState,TargetCapture,GuestAgent,Program,FirstRunorTelemetryran: 804 passed and 23 were skipped. The skipped ones are live tests that need an opt-in environment variable.scripts\validate-plugin-package.ps1passes.main: the Release test build had 0 warnings, 448 tests matchingSandbox,InteractiveDesktopPathsorExecutionTargetran (438 passed, 10 skipped live tests), andscripts\validate-plugin-package.ps1passed.scripts\build-cli.ps1 -SkipTests -SkipNpm -SkipMsixsucceeded with no generated-doc changes.Compatibility. Several parts handle state left by v0.7.0:
The
adoptedkey was removed from the minimized-window error context. It was never documented.Possible follow-ups (not in this PR):
@electron-internal/extract-zipfail with a misleading "prebuild not bundled" error. The real cause is the missing VC++ runtime in the guest.