Repository navigation
sandbox: refuse a restore's share of its snapshot store at provision - #2309
Merged
Pedro Henrique Penna (ppenna) merged 1 commit intoNov 28, 2026
Merged
Conversation
`nvx snapshot restore` with a `--mount` that reaches its snapshot store, such as `--mount /data,STORE,ro`, failed with the refusal of the sandbox's first start, "sandbox mount host path STORE overlaps the sandbox's snapshot store STORE", but only after its provision had recorded the sandbox (#2306). Every later `sandbox start` refused it again, and a corrected `snapshot restore` into the same state directory failed with `sandbox-provisioned` until the sandbox was deprovisioned. The provision branch of `run_from` refused shares of the sandbox's own files with `refuse_own_files` against its state directory, image, scratch image, and artifacts, but not against the snapshot store of its `source`, which each start of a restored sandbox checks with a second call. `lifecycle::provision` documents that it refuses a configuration that every start would refuse, as #2159 established; its `check_record` covers the kernel command line and block paths, not the shares. Make the provision of a restored sandbox refuse a share of its snapshot store as each start does, before it records anything. Start keeps its check, since a share may come to resolve into the store after the provision. `run --restore-snapshot`, which refuses `--mount` for a restore, is unaffected. `doc/run.md` now says that the provision of `snapshot restore` refuses such a share too. Tests: the new test snapshot_restore_refuses_a_share_of_its_snapshot_store_before_it_provisions runs `snapshot restore` with a share of the store and of a directory inside it. At b269fea it fails, since the state directory exists after the refusal, and with this change it passes, on Windows and on Linux (WSL). The local gates that the change selects pass on Windows; on Linux all pass but nvx-cli, whose requirements WSL's externally managed Python refuses to install. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change to reject snapshot-store-overlapping mounts before recording sandbox state.
No open issues 🎉
What changed in this PR
This PR fixes #2306 by making nvx snapshot restore reject mounts that overlap its snapshot store before recording sandbox state. This prevents failed restores from leaving behind a provisioned sandbox that cannot start.
Changes:
- Reuses the existing overlap check during provisioning while preserving checks at every start.
- Adds regression coverage for sharing the store itself or a subdirectory, verifying rejection leaves no sandbox state and launches no VM.
- Documents the provision-time snapshot-store check.
| File | Description |
|---|---|
nvx/src/host/cli/sandbox/mod.rs |
Checks restored sandboxes’ shares against their snapshot store before provisioning. |
nvx/src/host/cli/sandbox/lifecycle/start/tests/restore.rs |
Adds regression coverage for early refusal without leftover sandbox state. |
doc/run.md |
Clarifies when provisioning and start reject snapshot-store shares. |
Review effort: Balanced
Pedro Henrique Penna (ppenna)
deleted the
agents/issue-2306-restore-store-share
branch
November 28, 2026 15:55
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.
Fixes #2306
What does this pull request change?
nvx snapshot restorenow refuses a--mountwhose host path equals,contains, or lies inside its snapshot store before it provisions anything,
with the same error that each start of the sandbox gives:
Before this change, the command reported that error only from the sandbox's
first
start, after its provision had recorded the sandbox in--state-dir.Every later
nvx sandbox startrefused the sandbox again, and a correctedsnapshot restoreinto the same state directory failed withsandbox-provisioneduntil the user rannvx sandbox deprovision.nvx/src/host/cli/sandbox/mod.rs: theprovision branch of
run_fromcallsrefuse_own_filesa second time whenthe sandbox restores a snapshot, with the snapshot store of its
source,as each start of a restored sandbox does. Start a review here.
doc/run.md: the paragraph on shares of a sandbox's own filessays that the provision of
snapshot restorerefuses a share of thesnapshot store too.
nvx/src/host/cli/sandbox/lifecycle/start/tests/restore.rs.Left as it was:
startkeeps its own check, since a share's resolved path cancome to reach the store through a link after provision.
run --restore-snapshotis unaffected, since it refuses
--mountfor a restore. Hard links and bindmounts of the store's files are still not detected, as
doc/run.mdsays.Why is this change needed?
Root cause:
snapshot restoreprovisions its sandbox throughrun_fromandthen starts it. The provision branch checked the shares with
refuse_own_filesagainst the sandbox's state directory, image, scratch image, and artifacts, but
not against the snapshot store that its
sourcenames, althoughrefuse_own_fileslists "a restored sandbox's snapshot store" among thedirectories that it guards, and every start of a restored sandbox makes that
second call.
lifecycle::provisiondocuments that it refuses a configurationthat every start would refuse, as #2159 established; #2165 made it apply
check_record, which covers the kernel command line and, for a restoredsandbox, its block paths, but not the shares. The start-side refusal arrived
with
snapshot restorein #1486, so provision never applied it.Alternatives considered:
refuse_own_filescall, by letting it takeseveral directories, would also change
start's two calls. The added callmirrors
startline for line, which keeps the change to the provision path.lifecycle::provisionorcheck_record: neither seesthe export plan with the shares' resolved host paths that
run_fromalreadyholds, and
run_fromis where provision checks the sandbox's other ownfiles.
How was this change validated?
Checks and results:
nvx/:cargo test --locked --all-features --lib snapshot_restore_refuses_a_share_of_its_snapshot_store_before_it_provisions.It fails at
b269fea351a, with the fix'ssandbox/mod.rsreplaced by thebase's, at
restore.rs:974, since the state directory exists after therefusal; it passes with the fix. Both results on Windows (this
workstation) and on Linux (WSL), at commit
0fe1ceafbcd, whose tree(
284505fc621) the pushed head1c7d89dd33dkeeps; only the commit messagechanged since.
python scripts/local_gates.py --base origin/dev --runon Windows, with therelease
nvxbuilt so thatNVXnames it: all 9 selected gates passed:test-changes, markdown-links, test-layout, nvx-format, nvx-lint, nvx-test
(lib, all features: 1185 passed, 0 failed, 20 ignored), nvx-doc, nvx-msrv,
and nvx-cli (2326 tests OK, 89 skipped; 84 tests OK, 11 skipped).
python3 scripts/local_gates.py --base origin/dev --runin WSL: 12 of 13selected gates passed: test-changes, markdown-links, test-layout,
nvx-format, nvx-lint, nvx-test, nvx-doc, nvx-public-api, nvx-msrv,
nvx-macos, nvx-guest-binaries-lint, and nvx-guest-binaries-build.
nvx-cli was blocked: its first step,
python3 -m pip install --requirement scripts/setup/azure/requirements.txt,fails with PEP 668's
externally-managed-environmentin WSL's systemPython, which this session may not change. Its tests passed on Windows.
python scripts/check_test_layout.py: passed.python scripts/check_test_changes.py --base origin/dev:0 change(s) to existing tests; relocated unchanged: 0; added: 1.cargo fmt --all --checkandcargo clippy --locked --all-targets --all-features -- -D warnings: cleanon Windows.
Remote runs before and after the fix:
No configured NVX host was reachable, so the runs used this workstation's
fallbacks; none launches a VM, since the refusal precedes any launch.
b269fea351a)azure-intel-whp-1to-7,-11,-12, andazure-amd-whp-1to-4config.jsonbehindazure-intel-kvm-1to-5,-7, andazure-amd-kvm-1to-4azure-intel-mshv-1to-5,-8, andazure-amd-mshv-1to-4were unreachable, and mshv has no local fallbackLeft to CI: mshv, which no host could run here; the Linux nvx-cli gate, blocked in WSL; and the microVM scenarios and benchmarks of every backend, which this pre-launch refusal does not change.
Checklist
python3 scripts/check_test_layout.pychecks.python3 scripts/check_test_changes.py --base origin/devlists no changeto an existing test, or a Changes to existing tests section below
explains each one.
.github/copilot-instructions.mdand the skills when a convention orworkflow changes.
nvxupdatesnvx/public-api/withpython3 scripts/public_api.py --update.description says how the change versions or migrates them.