Add the Windows Sandbox state-aware lifecycle + host daemon (Phase 2)#578
Open
MGudgin wants to merge 2 commits into
Open
Add the Windows Sandbox state-aware lifecycle + host daemon (Phase 2)#578MGudgin wants to merge 2 commits into
MGudgin wants to merge 2 commits into
Conversation
91e0bab to
5d411b0
Compare
3 tasks
9d5d7e5 to
e3ccb02
Compare
569651e to
1830960
Compare
dhoehna
reviewed
Jul 8, 2026
| The wire spec and the SDK observably disagree on *which* error fires for an | ||
| unrecognised prefix, and this is by design: | ||
|
|
||
| | Source | Behaviour for an unrecognised `sandboxId` prefix | |
There was a problem hiding this comment.
(Very small) NIT: One of your previous PR's you did not add a u to honor. Pick a spelling style and stick with it.
dhoehna
reviewed
Jul 8, 2026
| } | ||
|
|
||
| // WindowsSandbox holds a single active sandbox behind a persistent host-side | ||
| // daemon. It has no Entra/`user` bundle. Filesystem policy is honored at |
dhoehna
reviewed
Jul 8, 2026
| // IsolationSession returns no metadata for start, stop, deprovision | ||
| }; | ||
| windows_sandbox?: Record<never, never>; | ||
| // ^ WindowsSandbox returns no metadata for any phase (keyof never -> undefined) |
dhoehna
reviewed
Jul 8, 2026
|
|
||
| ## State-aware lifecycle | ||
|
|
||
| In addition to the one-shot path above, Windows Sandbox supports the **state-aware lifecycle** — a multi-call `provision → start → exec* → stop → deprovision` flow that holds a single live VM across separate `wxc-exec` phase processes. This mirrors the cross-backend state-aware API (see [`docs/state-aware-lifecycle/mxc-state-aware-sandbox-api.md`](../state-aware-lifecycle/mxc-state-aware-sandbox-api.md)) and is the integrated, long-lived counterpart to the disposable one-shot runner. |
There was a problem hiding this comment.
Does Windows Sandbox support any other flows besides the state-aware lifecycle?
dhoehna
reviewed
Jul 8, 2026
| /// The connection was lost or left in an indeterminate state by a failed | ||
| /// exec or reconnect. Every subsequent `EXEC` deterministically returns | ||
| /// `ERR <reason>`; `STOP`/teardown still work. | ||
| Poisoned(String), |
There was a problem hiding this comment.
Consider changing poisoned to a description not a violent. Maybe ConnectionLostOrIndeterminateState
Consideing the comments say or should this be split into two enums?
dhoehna
reviewed
Jul 8, 2026
| /// EXEC. The caller writes `OK\n` and proceeds. | ||
| Admit, | ||
| /// Another EXEC currently holds the slot mutex. The caller writes | ||
| /// `ERR busy\n` and returns. No state is mutated. |
There was a problem hiding this comment.
Future developers might not know to modify this comment if they change the behavior of the caller. Or if the state is changed. Consider not putting implementation details in comments so far away from the source code.
dhoehna
reviewed
Jul 8, 2026
| // Bounded-wait acquire: wait up to | ||
| // PREAUTH_PERMIT_WAIT for a permit so a transient | ||
| // make-j-style burst that briefly exceeds | ||
| // MAX_CONCURRENT_PREAUTH does not surface as a spurious |
dhoehna
approved these changes
Jul 8, 2026
8e2cb9b to
22cfc41
Compare
1830960 to
9728f3d
Compare
22cfc41 to
d140ea9
Compare
9728f3d to
e7957bc
Compare
daa4c4a to
153e927
Compare
5c49b06 to
11367a7
Compare
e7957bc to
e562263
Compare
This PR rewrites the Windows Sandbox one-shot backend onto a fresh-VM lifecycle with an authenticated host-to-guest protocol and ownership-scoped teardown, and fixes non-elevated feature detection. Details * Adds `windows_sandbox_lifecycle` for policy validation, launch, rendezvous, execution, crash recovery, and guaranteed teardown of each disposable VM. * Authenticates every TCP channel with a per-launch nonce and channel role, and hardens guest process-tree cleanup and firewall isolation. * Routes the runner through `mxc_engine`, removes the host Python and warm-daemon dependencies, and warns only when non-default legacy daemon settings are ignored. * Rejects an existing Tokio runtime before host mutation or stdin-thread creation, avoiding a blocking thread leak on the error path. * Treats the state-aware daemon as optional in the Phase 1 SDK package; later stack phases build and require it. * Updates one-shot tests and documentation for the supported filesystem/network policy, protocol, security model, and debugging workflow. Tests * `cargo fmt --all -- --check` * `cargo check --workspace --all-targets` * `cargo clippy --workspace --all-targets -- -D warnings` * `cargo test --workspace --exclude wxc_host_prep` * `cargo check -p mxc_engine -p wxc --all-features` * `npm run build` (from `sdk`) Fixes #560 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c03d0923-5577-4c56-b2df-a314428f5164 Generated-with: claude-opus-4.8 Generated-with: gpt-5.6-sol
11367a7 to
501432b
Compare
This PR adds the multi-invocation Windows Sandbox lifecycle on top of the authenticated one-shot backend. Details * Implements provision, start, repeated single-flight exec, stop, and deprovision through `WindowsSandboxRunner` and durable owner-only records. * Adds a detached host daemon that owns the live VM, authenticates localhost IPC, reconnects guest data channels, and reclaims only provably-owned orphans. * Routes state-aware backend selection through `mxc_engine` with experimental gating, keeping `wxc-exec` as a thin CLI shell. * Enforces terminal-exit ordering with a daemon-local release token that can be created only after restoring and unlocking the guest slot. * Adds state-aware documentation and Windows Sandbox lifecycle E2E coverage. Tests * `cargo fmt --all -- --check` * `cargo check --workspace --all-targets` * `cargo clippy --workspace --all-targets -- -D warnings` * `cargo test --workspace --exclude wxc_host_prep` * `cargo check -p mxc_engine -p wxc --all-features` Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c03d0923-5577-4c56-b2df-a314428f5164 Generated-with: claude-opus-4.8 Generated-with: gpt-5.6-sol
e562263 to
b29b708
Compare
501432b to
1124ea8
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.
Note
Stacked on #577 (which is stacked on #576). This PR's base is
user/gudge/wsb-phase1-one-shot, so the diff shows only the Phase 2 commit.Merge order: #576 -> #577 -> this PR. GitHub auto-retargets the base to
mainas each parent merges and its branch is deleted.
.github/copilot-instructions.md.Summary
Phase 2 of the Windows Sandbox rewrite stack: add the state-aware lifecycle
(
provision -> start -> exec* -> stop -> deprovision) for Windows Sandbox on topof the Phase 1 one-shot rewrite, holding a single live VM across separate
wxc-execphase processes behind a persistent detached host-side daemon. The SDKfollows in Phase 3.
Details
windows_sandbox_lifecycle: re-enablesstate_aware.rs-- theStatefulSandboxBackendimpl onWindowsSandboxRunner.provisionvalidates +snapshots the filesystem policy and mints
wsb:<token>;startspawns thedetached daemon (which boots the VM and holds the guest control connection);
execrelays a script over the held connection;stop/deprovisiontear down.A process-global named mutex serialises start/stop/deprovision; the single host
VM slot is enforced.
wxc_windows_sandbox_daemon):control_server.rsserves anonce-authenticated localhost line protocol (
PING/STOP/EXEC), eachconnection on its own task so a long exec can't block a
STOP. Auth nonce viastdin; sandbox token via
--token. Re-added to the workspace members (droppedin Phase 1); the legacy
pipe_server/sandbox_vm/tcp_bridge/rendezvousmodules are deleted (rendezvous now lives in the lifecycle crate).
run_state_awareroutes thewsb:prefix toWindowsSandboxRunnerwith the same--experimentalgate as one-shot;state_aware_dispatchlearns thewsb-> WindowsSandbox prefix mapping.windows-sandbox.md/windows-sandbox-reference.md,schema.md(dual-modebackend row + state-aware envelope section), the state-aware API doc, and
copilot-instructions.md. While touchingschema.mdI reconciled its versiontable to the canonical
schemas/schema-version.json(>=0.4, <=0.8; stable0.7.0-alpha; state-aware 0.6.0-alpha) -- the rewrite had left it at the pre-0.8
<=0.7.run_windows_sandbox_state_aware_tests.ps1(state-aware E2E).Tests
cargo check --workspace --all-targets,cargo clippy --workspace --all-targets -- -D warnings, andcargo fmt --all -- --check: clean.cargo test: windows_sandbox_lifecycle 157 (incl. the state-aware suite),wxc_windows_sandbox_daemon 23, wxc_common 364 (incl. the new
wsbresolvertest), wxc 13 -- all passed.
node scripts/versioning/check-schema-versions.js: green.Related Issues
Microsoft Reviewers: Open in CodeFlow