Skip to content

Instantly share code, notes, and snippets.

@jsturtevant
Last active April 6, 2026 20:56
Show Gist options
  • Select an option

  • Save jsturtevant/386ae7db51ba0d3b306085aab472273a to your computer and use it in GitHub Desktop.

Select an option

Save jsturtevant/386ae7db51ba0d3b306085aab472273a to your computer and use it in GitHub Desktop.
Hyperlight PyPI sample with self-contained venv and async tool registration
Hyperlight sample using uv
Requires: uv (https://docs.astral.sh/uv/getting-started/installation/)
Run the verified sample with:
bash /tmp/hyperlight-testpypi-sample/run_sample.sh
The sample registers one simple async host tool named `echo` and calls it from
both the Python and JavaScript guests.
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
uv run --no-project \
--with 'hyperlight-sandbox[wasm,python_guest,javascript_guest]' \
python "$SCRIPT_DIR/sample_verify.py"
import asyncio
try:
from hyperlight_sandbox import Sandbox
except ImportError as exc:
raise SystemExit(
"hyperlight_sandbox is not installed in this interpreter. Run this script with "
"run_sample.sh or install the package first."
) from exc
def run_case(module_ref: str, code: str) -> None:
sandbox = Sandbox(backend="wasm", module=module_ref)
async def host_echo(message="ok"):
await asyncio.sleep(0)
return f"host:{message}"
sandbox.register_tool("echo", host_echo)
result = sandbox.run(code)
if not result.success:
raise SystemExit(f"{module_ref} failed: {result.stderr}")
print(f"{module_ref}: {result.stdout.strip()}")
run_case("python_guest.path", 'print(call_tool("echo", message="python guest ok"))')
run_case("javascript_guest.path", 'console.log(call_tool("echo", { message: "javascript guest ok" }));')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment