Repository navigation
[BREAKING] Python: fix(hyperlight): interrupt guest execution and enforce time limits - #10152
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 7 commits intoNov 11, 2026
Conversation
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.
Motivation & Context
Cancelling an asynchronous Hyperlight invocation should stop its guest execution before the sandbox can be reused. Python guest execution also needs a finite default budget, consistent with the .NET work in #10066.
Description & Review Guide
execution_timeout_secondsoption to the tool and provider, defaulting to 30 seconds. Forward cancellation through an independently owned SDK interruption handle, wait for the native worker and interruption monitor to finish, and restore the warm snapshot before reuse. Capture the setting in provider run snapshots and serialized state. Add focused unit and real-guest regressions and update consumer guidance.asyncio.CancelledError. Runtime initialization and host tool callbacks cannot be interrupted and must enforce their own limits.Dependency prerequisite: This draft requires the Python
Sandbox.interrupt_handle()API from hyperlight-dev/hyperlight-sandbox#275. The declared released dependency does not yet provide it. A compatible SDK release and dependency-floor update are required before shipping; no local source paths are committed.Validation used temporary Linux x64 Azure KVM containers linked to SDK revision
530672881443ac26973688191a18f180dc373efd. The three original real-guest regressions failed for the intended behavior before implementation changes.Commands below ran from
python/packages/hyperlightwith that source-linked environment:python -m pytest tests/hyperlight/test_execution_limits.py tests/hyperlight/test_execution_control.py -v --tb=shortwithHYPERLIGHT_RUN_GUEST_TESTS=true: 8 passed, covering Python/Wasm and native JavaScript.python -m pytest tests -k "not pings_bing" --tb=shortwithHYPERLIGHT_RUN_GUEST_TESTS=true: 267 passed, 6 platform skips, 1 deselected, with the pre-existing warning described below.python -m pytest tests -k pings_bing --tb=shortwith networking enabled: 1 passed.python -m pytest -m 'not integration' --cov=agent_framework_hyperlight --cov-report=term-missing:skip-covered --cov-fail-under=85 tests --tb=short: 247 passed, 6 platform skips, 21 deselected; 88.31% coverage, above the 85% gate.ruff check --no-fix .andruff format --check .: passed with the repository-pinned Ruff.pyright --pythonpath /src/.venv/bin/python: passed, 0 errors for source.The configured test-typing profiles ran from
python:mypy --config-file pyproject.toml --explicit-package-bases --namespace-packages --python-executable /src/.venv/bin/python packages/hyperlight/tests: passed.pyrefly check -c pyrefly.toml packages/hyperlight/tests: passed.ty check packages/hyperlight/tests: passed.zuban mypy --config-file pyproject.toml packages/hyperlight/tests: passed.pyright -p pyrightconfig.tests.json --pythonpath /src/.venv/bin/python packages/hyperlight/tests: passed.The full package run reports a native
WasmSandboxcross-thread finalization warning. Repeating the existing host-error and owner-thread tests with unchanged production code frommainand the same SDK reproduces it:python -m pytest tests/hyperlight/test_hyperlight_codeact.py -k 'host_error_policy_with_real_sandbox or sandbox_run_result_is_finalized_on_owner_thread' --tb=short -W error::pytest.PytestUnraisableExceptionWarningproduced 4 passed, 1 failed because the warning was promoted to an error. This draft does not claim that existing warning is fixed.Cross-language checks used the same updated SDK and the unchanged #10066 source.
/srcwas the SDK checkout and/linked-sdk.targetsreplaced the .NET package reference with its local project:python -m unittest discover -s src/sdk/python/core/tests -p test_interruption.py -v: 4 passed, each exercising both backends.dotnet vstest /src/src/sdk/dotnet/core/Tests/HyperlightSandbox.Tests/bin/Debug/net8.0/HyperlightSandbox.Tests.dll --Logger:"console;verbosity=normal": 152 passed.dotnetdirectory,dotnet test --project tests/Microsoft.Agents.AI.Hyperlight.UnitTests -f net10.0 --no-build --no-restore -p:CustomAfterMicrosoftCommonTargets=/linked-sdk.targets -p:HyperlightGuestTests=true: 62 passed, 0 skipped.dotnet test --project tests/Microsoft.Agents.AI.Hyperlight.IntegrationTests -f net10.0 --no-build --no-restore -p:CustomAfterMicrosoftCommonTargets=/linked-sdk.targets -p:JsonSerializerIsReflectionEnabledByDefault=true: 5 passed, 0 skipped.Temporary Azure resources were deleted and their absence verified.
Related Issue
Related to #10066, which implements the .NET counterpart. This PR implements the Python integration rather than duplicating that work.
Depends on hyperlight-dev/hyperlight-sandbox#275. No separate Agent Framework issue is linked.
AI Assistance
AI assistance details: GitHub Copilot assisted with implementation, regression tests, documentation, validation, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.