Skip to content

fix: support cancellation during sandbox execution - #275

Open
baywet wants to merge 1 commit into
hyperlight-dev:mainfrom
baywet:fix/sandbox-interruption
Open

baywet wants to merge 1 commit into
hyperlight-dev:mainfrom
baywet:fix/sandbox-interruption

Conversation

@baywet

@baywet baywet commented Nov 4, 2026

Copy link
Copy Markdown

Summary

Related to #9.

Expose independently owned native interruption handles through the Rust backend abstraction and .NET FFI. Add Sandbox.Run(string, CancellationToken) and make RunAsync forward cancellation into running guest execution, while preserving Run(string).

Cancellation uses a dedicated interruption worker, retries the transition into guest execution, and waits for native execution and cancellation work to finish before returning. The callback never accesses mutable sandbox state or acquires the execution gate. Existing snapshot/restore behavior permits reuse after interruption.

There is no implicit SDK deadline: hosts can supply a timeout-backed CancellationTokenSource. Runtime initialization and host callbacks cannot be interrupted; host tools need their own cancellation policy.

Validation

Executed in Ubuntu x64 containers on a KVM-capable host using .NET SDK 10.0.403 and Rust 1.94. The net8.0 tests ran with DOTNET_ROLL_FORWARD=Major.

  • Before the implementation: dotnet vstest src/sdk/dotnet/core/Tests/HyperlightSandbox.Tests/bin/Debug/net8.0/HyperlightSandbox.Tests.dll --TestCaseFilter:FullyQualifiedName~JavaScript_RunAsync_CancellationDuringExecution_StopsGuestAsync --Logger:"console;verbosity=normal" failed as expected after a genuine warm-up and five seconds of guest execution: expected OperationCanceledException, but none was thrown.
  • just wasm guest-build — passed, building the actual Python/Wasm guest.
  • just fmt and just fmt-check — passed.
  • just lint-rust and just dotnet lint-rust — passed.
  • dotnet build src/sdk/dotnet/core/Tests/HyperlightSandbox.Tests/HyperlightSandbox.Tests.csproj --nologo -p:TreatWarningsAsErrors=true — passed, zero warnings/errors.
  • just test-rust — passed, 144 unit tests and 5 HTTP integration tests; one existing documentation example remains ignored.
  • just dotnet test-rust — passed, 78 FFI tests.
  • dotnet vstest src/sdk/dotnet/core/Tests/HyperlightSandbox.Tests/bin/Debug/net8.0/HyperlightSandbox.Tests.dll --Logger:"console;verbosity=normal" — passed, all 147 tests, including real JavaScript immediate/timer cancellation and recovery, pre-canceled execution, isolation from completed cancellation registrations, and Python/Wasm interruption followed by snapshot restoration.

The first Rust HTTP run failed because a network-disabled container could not resolve the existing HTTPS test's destination. The full Rust suite passed when run with its required networking. FFI and .NET guest tests remained resource-limited and network-disabled.

Windows execution, the Python SDK suite, and package publishing were not run locally; upstream CI remains pending. This PR must remain a draft.

AI assistance

Copilot assisted with implementation, tests, documentation, and this description.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3d6807e7-70a6-4c43-8dc1-7bab20376cd4
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@baywet
baywet force-pushed the fix/sandbox-interruption branch from 25eecb7 to 280a15c Compare November 4, 2026 00:37
@baywet
baywet marked this pull request as ready for review November 4, 2026 12:05

This branch has not been deployed

No deployments
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.

1 participant