Skip to content

sandbox: refuse a restore's share of its snapshot store at provision - #2309

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2306-restore-store-share
Nov 28, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2306-restore-store-share

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #2306

What does this pull request change?

nvx snapshot restore now refuses a --mount whose 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:

error[unsupported]: sandbox mount host path STORE overlaps the sandbox's snapshot store STORE; a share cannot expose the sandbox's own files

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 start refused the sandbox again, and a corrected
snapshot restore into the same state directory failed with
sandbox-provisioned until the user ran nvx sandbox deprovision.

  • nvx/src/host/cli/sandbox/mod.rs: the
    provision branch of run_from calls refuse_own_files a second time when
    the 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 files
    says that the provision of snapshot restore refuses a share of the
    snapshot store too.
  • A regression test in
    nvx/src/host/cli/sandbox/lifecycle/start/tests/restore.rs.

Left as it was: start keeps its own check, since a share's resolved path can
come to reach the store through a link after provision. run --restore-snapshot
is unaffected, since it refuses --mount for a restore. Hard links and bind
mounts of the store's files are still not detected, as doc/run.md says.

Why is this change needed?

Root cause: snapshot restore provisions its sandbox through run_from and
then starts it. The provision branch checked the shares with refuse_own_files
against the sandbox's state directory, image, scratch image, and artifacts, but
not against the snapshot store that its source names, although
refuse_own_files lists "a restored sandbox's snapshot store" among the
directories that it guards, and every start of a restored sandbox makes that
second call. lifecycle::provision documents that it refuses a configuration
that every start would refuse, as #2159 established; #2165 made it apply
check_record, which covers the kernel command line and, for a restored
sandbox, its block paths, but not the shares. The start-side refusal arrived
with snapshot restore in #1486, so provision never applied it.

Alternatives considered:

  • Folding the store into the first refuse_own_files call, by letting it take
    several directories, would also change start's two calls. The added call
    mirrors start line for line, which keeps the change to the provision path.
  • Moving the check into lifecycle::provision or check_record: neither sees
    the export plan with the shares' resolved host paths that run_from already
    holds, and run_from is where provision checks the sandbox's other own
    files.

How was this change validated?

Checks and results:

  • Regression test, in 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's sandbox/mod.rs replaced by the
    base's, at restore.rs:974, since the state directory exists after the
    refusal; it passes with the fix. Both results on Windows (this
    workstation) and on Linux (WSL), at commit 0fe1ceafbcd, whose tree
    (284505fc621) the pushed head 1c7d89dd33d keeps; only the commit message
    changed since.
  • python scripts/local_gates.py --base origin/dev --run on Windows, with the
    release nvx built so that NVX names 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 --run in WSL: 12 of 13
    selected 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-environment in WSL's system
    Python, 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 --check and
    cargo clippy --locked --all-targets --all-features -- -D warnings: clean
    on Windows.
  • A code-review pass over the whole diff found no significant issues.

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.

Where Backend Host type Before (b269fea351a) After (fix)
This workstation, Windows 11, local fallback for the unreachable azure-intel-whp-1 to -7, -11, -12, and azure-amd-whp-1 to -4 whp (no VM launched) n/a (local) Regression test fails; the reproduction of #2306 leaves config.json behind Passes
Default WSL 2 distribution, fallback for the unreachable azure-intel-kvm-1 to -5, -7, and azure-amd-kvm-1 to -4 kvm (no VM launched) n/a (WSL) Regression test fails Passes
None: azure-intel-mshv-1 to -5, -8, and azure-amd-mshv-1 to -4 were unreachable, and mshv has no local fallback mshv — Not run Left to CI

Left 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

  • Tests cover the new or fixed behavior, in the layout that
    python3 scripts/check_test_layout.py checks.
  • python3 scripts/check_test_changes.py --base origin/dev lists no change
    to an existing test, or a Changes to existing tests section below
    explains each one.
  • The documentation that the change affects is updated, including
    .github/copilot-instructions.md and the skills when a convention or
    workflow changes.
  • A change to the public API of nvx updates nvx/public-api/ with
    python3 scripts/public_api.py --update.
  • Snapshots, protocols, and on-disk formats stay compatible, or the
    description says how the change versions or migrates them.

`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>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 04:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 28, 2026
Merged via the queue into dev with commit 946527f Nov 28, 2026
56 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-2306-restore-store-share branch November 28, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nvx: snapshot restore provisions a sandbox whose --mount reaches its snapshot store, which every start refuses

2 participants