Propagate guest exit codes and implement host-mediated time.sleep - #20
Merged
Conversation
Three behavioral fixes for python-agent-driver on Hyperlight: 1. Exception exit codes: PyRun_SimpleString swallowed exceptions. Replace with PyRun_String + manual exception handling in run_code_with_exceptions(). Non-zero exit codes reported to host via __hl_exit /dev/hcall side channel. 2. sys.exit(N) propagation: SystemExit was caught by CPython's internal handler which called exit() — Hyperlight's VmExit::Halt doesn't carry exit codes. Now intercepted before CPython handles it, code extracted and reported via __hl_exit. 3. time.sleep() was a no-op: Unikraft's cooperative scheduler on Hyperlight has no timer interrupt, so nanosleep returns immediately. Monkey-patch time.sleep during init to route through __hl_sleep host call, which blocks the host thread. Host side: Sandbox gains exit_code field (Arc<AtomicI32>), always registers __dispatch with __hl_exit and __hl_sleep handlers via register_internal_tools(). RunTiming exposes exit_code. pyhl binary exits with the guest's reported code. Signed-off-by: danbugs <danilochiarlone@gmail.com>
danbugs
marked this pull request as ready for review
May 13, 2026 02:06
danbugs
enabled auto-merge
May 13, 2026 02:06
Contributor
There was a problem hiding this comment.
Linux Benchmarks
Details
| Benchmark suite | Current: 2270ef1 | Previous: 35c26ff | Ratio |
|---|---|---|---|
hello_world (median) |
20 ms |
20 ms |
1 |
pandas (median) |
100 ms |
100 ms |
1 |
density (per VM) |
6 MB |
6 MB |
1 |
snapshot (disk) |
648 MiB |
648 MiB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
Contributor
There was a problem hiding this comment.
Windows Benchmarks
Details
| Benchmark suite | Current: 2270ef1 | Previous: 35c26ff | Ratio |
|---|---|---|---|
hello_world (median) |
237 ms |
281 ms |
0.84 |
pandas (median) |
819 ms |
983 ms |
0.83 |
density (per VM) |
6 MB |
6 MB |
1 |
snapshot (disk) |
673 MiB |
673 MiB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
Signed-off-by: danbugs <danilochiarlone@gmail.com>
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.
Summary
PyRun_SimpleString(which swallows exceptions) withPyRun_String+ manual exception handling.SystemExitcodes are extracted (e.g.sys.exit(42)→ exit code 42), other exceptions set exit code 1 with traceback printed. Non-zero codes reported to host via__hl_exit/dev/hcallside channel.time.sleep: Unikraft's cooperative scheduler on Hyperlight has no timer interrupt, sonanosleepreturns immediately. Monkey-patchtime.sleepduring init to route through__hl_sleephost call, which blocks the host thread for the requested duration.Sandboxgainslast_exit_code()/reset_exit_code()backed byArc<AtomicI32>.RunTimingexposesexit_code.pyhlbinary exits with the guest's reported code.