Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ pyhl run my_script.py
pyhl run my_script.py --repeat 4 # 5 hermetic invocations
```

Each `pyhl run` process pays a ~10s cold start (kernel boot + Py_Initialize
+ preloaded imports) once, then every user invocation (including the
first) runs hermetic at ~100ms — the driver snapshots the post-warmup
state and restores between calls, so `__main__` globals and `sys.modules`
don't leak between runs.
Each `pyhl run` process pays a one-time warmup (~3 s for `Py_Initialize` +
preloaded imports) on first call, then snapshots the post-warmup state.
Every invocation thereafter (including subsequent calls in the same process
and `--repeat` iterations) restores from the snapshot and runs hermetic
at ~100 ms — `__main__` globals and `sys.modules` don't leak between runs.

`pyhl setup` is idempotent — re-running reports the existing install and
exits 0; pass `--force` to overwrite. Artifacts are found via
Expand Down
59 changes: 2 additions & 57 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! - [`Sandbox::save_snapshot`] writes the current snapshot to disk.
//! - [`Sandbox::from_snapshot_file`] recreates a sandbox straight from
//! the file on disk, bypassing evolve entirely. This is how
//! `pyhl run` starts in ~200ms without re-doing `Py_Initialize`.
//! `pyhl run` starts in ~100ms without re-doing `Py_Initialize`.
//!
//! # Host filesystem
//!
Expand Down Expand Up @@ -2213,64 +2213,9 @@ impl Sandbox {
}

// ---------------------------------------------------------------------------
// Convenience: run_vm (single-shot execution)
// Convenience: run_vm_capture_output (single-shot execution with output)
// ---------------------------------------------------------------------------

/// Run a Unikraft kernel to completion (single-shot). Thin shim over
/// [`Sandbox::builder`] for callers that don't need the full fluent API.
pub fn run_vm(
kernel_path: &Path,
initrd: Option<&[u8]>,
app_args: &[String],
config: VmConfig,
) -> Result<()> {
let _ = Sandbox::evolve_inline(kernel_path, initrd, app_args, config, None, &[], None, None)?;
Ok(())
}

/// Run a Unikraft kernel with tool dispatch support.
pub fn run_vm_with_tools(
kernel_path: &Path,
initrd: Option<&[u8]>,
app_args: &[String],
config: VmConfig,
tools: ToolRegistry,
) -> Result<()> {
let _ = Sandbox::evolve_inline(
kernel_path,
initrd,
app_args,
config,
Some(tools),
&[],
None,
None,
)?;
Ok(())
}

/// Run a Unikraft kernel with preopened host directories exposed via
/// `lib/hostfs`. Sandbox escape attempts are rejected host-side.
pub fn run_vm_with_preopens(
kernel_path: &Path,
initrd: Option<&[u8]>,
app_args: &[String],
config: VmConfig,
preopens: &[Preopen],
) -> Result<()> {
let _ = Sandbox::evolve_inline(
kernel_path,
initrd,
app_args,
config,
None,
preopens,
None,
None,
)?;
Ok(())
}

/// Output captured from a VM execution.
pub struct VmOutput {
pub output: String,
Expand Down
Loading