⚠️ VIBE-CODED — AI-GENERATED, NOT PRODUCTION-READY
This project was written by an AI ("vibe coded"). It is experimental and has had no security review, fuzzing, or adversarial testing. It has only been smoke-tested on Linux (x86_64). Use at your own risk — do not rely on it for anything security-sensitive or mission-critical. See Limitations.
langchain-hyperlight
A LangChain tool that executes untrusted code inside a Microsoft Hyperlight micro virtual machine.
Hyperlight is a lightweight Virtual Machine Manager (VMM) designed to be embedded within applications. It runs untrusted code in hardware-isolated micro VMs (KVM, MSHV, or Hyper-V) with very low latency and minimal overhead. This package exposes that capability to LangChain agents as a standard tool, so an LLM can safely run arbitrary code without touching the host.
Features
- Hardware isolation — code runs in a micro VM, not on the host.
- Host tool dispatch — register host callables that guest code invokes by name with
schema-validated arguments (
call_tool(...)). - Capability-based file access — read-only
/input, writable/output, strict path isolation. - Network allow-listing — network is off by default; opt in per-domain and per-HTTP-verb.
- Snapshot / restore — capture and rewind sandbox state.
- Lazy sandbox creation — constructing the tool is cheap; the micro VM boots on first use.
Limitations
This is an early-stage, AI-generated integration. Be aware of the following before adopting it.
Platform
- x86_64 only. Hyperlight currently targets x86_64; there are no
aarch64(ARM) wheels. Raspberry Pi, Apple Silicon, and AWS Graviton are unsupported. - glibc 2.34+. The Rust backend ships
manylinux_2_34_x86_64wheels, so it needs a recent glibc. Works on Ubuntu 22.04+, Debian 12+, Fedora 36+, RHEL 9+. Does not work on Ubuntu 20.04, Debian 11, RHEL 8, or musl-based distros (Alpine, Void) without building the Rust backend from source. - Python 3.10–3.14.
- A hypervisor is required at runtime: KVM (
/dev/kvm) or MSHV on Linux. - Tested on Linux only. This package has only been tested on Linux (x86_64). It is not tested on Windows or macOS — use on those platforms at your own risk.
Security model
- The micro VM isolates the guest code you run, but any host tools you register via
host_toolsrun with full host privileges inside the sandbox'scall_tool(...). Only register callables you trust, and treat their inputs as untrusted. - Network is off by default and gated by
allowed_domains, but an allow-listed domain is reachable by any code running in the sandbox. - This package has not been security-reviewed. Do not treat it as a hardened sandbox boundary without your own audit.
Maturity
- Alpha / vibe-coded. No fuzzing, no adversarial testing, no cross-platform CI matrix.
- The thread-confinement worker (required because the
WasmSandboxisunsendablein PyO3) is correct for the tested paths but has not been stress-tested under heavy concurrency. host_toolsaccepts plain Python callables only — it does not yet wrap LangChainBaseToolinstances directly.
Installation
Platform support: this package is tested on Linux (x86_64) only. It is not tested on Windows or macOS — install and use on those platforms at your own risk.
pip install langchain-hyperlight
This pulls in langchain-core and hyperlight-sandbox[wasm,python_guest].
Prerequisite: a working hypervisor is required at runtime (not at install time):
- Linux: KVM (
/dev/kvm) or MSHV (/dev/mshv)
Quick start
from langchain_hyperlight import HyperlightSandboxTool
tool = HyperlightSandboxTool(
host_tools={
"add": lambda a=0, b=0: a + b,
"greet": lambda name="world": f"Hello, {name}!",
},
allowed_domains={"https://httpbin.org": ["GET"]},
)
result = tool.invoke({
"code": """
total = call_tool('add', a=3, b=4)
greeting = call_tool('greet', name='James')
print(f"3 + 4 = {total}")
print(greeting)
""",
})
print(result)
Using it inside an agent
from langchain_core.tools import create_agent # or your agent of choice
agent = create_agent(model, tools=[tool])
The tool is a standard langchain_core.tools.BaseTool, so it works with any LangChain agent
runtime (LangGraph, create_agent, AgentExecutor, etc.).
Relationship to Microsoft's Agent Framework
Microsoft ships an official Hyperlight integration for its own Agent Framework:
agent-framework-hyperlight
(HyperlightExecuteCodeTool / HyperlightCodeActProvider). This package is the LangChain
equivalent: it targets langchain_core.tools.BaseTool and mirrors the same concepts — the
execute_code tool name, file_mounts, allowed_domains, and host-tool dispatch via
call_tool(...) — so the mental model transfers directly.
Thread safety
The Hyperlight WasmSandbox is unsendable in PyO3: it may only be accessed and dropped from
the OS thread that created it, or it panics. This tool routes every sandbox operation through a
dedicated single-threaded worker, so it is safe to call from arbitrary threads and event loops
(including LangChain's async ainvoke).
Guest environment
By default the sandbox runs Python. Inside the guest, these built-ins are available:
| Function | Purpose |
|---|---|
call_tool(name, **kwargs) |
Invoke a host-registered tool by name |
http_get(url) / http_post(url, body=...) |
HTTP to allow-listed domains only |
read_file(path) / write_file(path, data) |
Capability-based file I/O (/input, /output) |
Configuration
HyperlightSandboxTool forwards its constructor arguments to
hyperlight_sandbox.Sandbox:
| Argument | Default | Description |
|---|---|---|
backend |
"wasm" |
"wasm" (Python/JS guest) or "hyperlight-js" |
module |
"python_guest.path" |
Packaged guest module reference |
module_path |
None |
Explicit path to a .aot/.wasm guest |
input_dir / output_dir |
None |
Host directories mounted into the guest |
temp_output |
False |
Use a temporary output directory |
heap_size / stack_size |
None |
Guest memory limits (e.g. "25Mi") |
host_tools |
{} |
{name: callable} exposed to the guest |
allowed_domains |
{} |
Network allow-list (see below) |
file_mounts |
{} |
Host paths staged into the guest /input tree (see below) |
allowed_domains accepts a domain string, a (target, methods) tuple, an AllowedDomain, or a
sequence of any of these:
from langchain_hyperlight import AllowedDomain
tool = HyperlightSandboxTool(
allowed_domains=[
"api.github.com", # all methods
("internal.example.com", "GET"), # GET only
AllowedDomain("https://httpbin.org", ("GET", "POST")),
],
)
file_mounts accepts a path string (same path on host and in the sandbox), a
(host_path, mount_path) tuple, a FileMount, or a sequence of any of these. Mounted files are
staged into a managed temporary /input tree and are readable in the guest via read_file(...):
from langchain_hyperlight import FileMount
tool = HyperlightSandboxTool(
file_mounts=[
"/host/data", # -> /input/data
("/host/models", "models"), # -> /input/models
FileMount("/host/config", "config"), # -> /input/config
],
)
The create_hyperlight_tool() factory is a thin convenience over the same constructor:
from langchain_hyperlight import create_hyperlight_tool
tool = create_hyperlight_tool(
host_tools={"add": lambda a=0, b=0: a + b},
allowed_domains=["api.github.com"],
)
Note: the tool always creates and owns its sandbox on a dedicated thread. Do not construct a
hyperlight_sandbox.Sandboxyourself and try to share it across threads — the underlyingWasmSandboxisunsendableand will panic if touched from a different thread than the one that created it. The tool manages this confinement for you.
Running on Bluefin / Fedora Silverblue (immutable)
Bluefin is an immutable Fedora (Silverblue) image. The package itself installs normally into a virtual environment, but the KVM hypervisor must be available on the host:
-
Verify virtualization is enabled in firmware (AMD-V / Intel VT-x):
grep -E 'vmx|svm' /proc/cpuinfo
-
Ensure the KVM device exists (the
kvm_amd/kvm_intelmodule is loaded):ls -l /dev/kvm
If it is missing, the module is not loaded. On Bluefin this is usually a firmware/BIOS setting (enable SVM/VT-x) rather than a package issue, since the kernel ships KVM.
-
Add your user to the
kvmgroup so you can open/dev/kvmwithout root:sudo usermod -aG kvm $USER # log out and back in, then verify: groups
-
Install the package in a venv (never layer Python packages system-wide on an immutable image — use
uv,pipx, or adistrobox/toolboxcontainer):uv venv .venv uv pip install --python .venv/bin/python langchain-hyperlight
For a fully isolated dev environment,
distroboxis the idiomatic Bluefin approach:distrobox create --name hyperlight-dev --image fedora:latest distrobox enter hyperlight-dev
Development
uv venv .venv
uv pip install --python .venv/bin/python -e ".[dev]"
.venv/bin/pytest
Tests that require a hypervisor are skipped automatically when /dev/kvm (or /dev/mshv) is
unavailable.
References
- Hyperlight project site — official docs and getting-started guide
- hyperlight-dev/hyperlight — the VMM itself
- hyperlight-dev/hyperlight-sandbox — the multi-backend sandbox framework this tool wraps
- hyperlight-dev/hyperlight-wasm — the Wasm component backend
- Microsoft Agent Framework Hyperlight integration —
the canonical
agent-framework-hyperlightpackage this tool mirrors - Microsoft Learn: Hyperlight integration
hyperlight-sandboxon PyPI
License
Apache-2.0. Hyperlight is a CNCF sandbox project.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_hyperlight-0.1.0.tar.gz.
File metadata
- Download URL: langchain_hyperlight-0.1.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Bluefin","version":"44","id":"Deinonychus","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f93a2a932a5d24ca1aaddc3d907bbe126c1586766a4e65da74467e113af4a05
|
|
| MD5 |
967c93caaff1aa704bf5fe1f147baeaf
|
|
| BLAKE2b-256 |
0dc0f355ae8df438cb731976d490d7ca902e2dad6dc9a9c182b0cd5239426ec4
|
File details
Details for the file langchain_hyperlight-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_hyperlight-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Bluefin","version":"44","id":"Deinonychus","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9de4d69055c9f2ba6b78ed15275d32bc21d87745ef268a4d051a134eb95721d2
|
|
| MD5 |
3f4e76df7bf0d67b0910bdcc9c655a37
|
|
| BLAKE2b-256 |
7206ad6a434217bad9a5fe9d7a2269752d7b393d43fb38c407e5726f2961815c
|