Skip to content

feat: add libkrun backend for macOS (vsock + native Hypervisor.framework) #142

@aniketmaurya

Description

@aniketmaurya

Problem

SmolVM uses QEMU on macOS, which has significant limitations:

  • Slirp networking: host cannot reach guest IP directly
  • No vsock support through SmolVM's QEMU backend
  • Port forwarding requires SSH tunnels (guest must run sshd)
  • Slow boot (~2-3s) compared to Firecracker on Linux (~500ms)

This forces users to either run SSH in their guest images or use workarounds like expose_local() for host→guest communication.

Proposal

Add libkrun as a third backend alongside Firecracker and QEMU.

libkrun is a lightweight VMM that uses Apple's Hypervisor.framework on macOS (and KVM on Linux). Key advantages:

  • Native virtio-vsock — direct host↔guest communication without networking
  • TSI (Transparent Socket Impersonation) — network connectivity without a virtual NIC
  • Fast boot — comparable to Firecracker (~500ms)
  • Lightweight — ~5MB library vs QEMU's ~200MB
  • OCI image support — can boot from container images via krunvm

Benefits

  • Unified vsock path: same guest agent communication on both Linux (Firecracker) and macOS (libkrun)
  • No SSH dependency: guest images don't need sshd for port forwarding
  • Faster dev loop: sub-second boot on macOS
  • Simpler networking: vsock replaces SSH tunnels + port forwarding

Implementation

  1. New runtime_libkrun.py adapter following the pattern of runtime_firecracker.py and runtime_qemu.py
  2. Add libkrun option to backend detection (auto selects libkrun on macOS if available, falls back to QEMU)
  3. vsock device configuration (already supported in VMConfig via feat: add virtio-vsock support for Firecracker VMs #141)
  4. Process management for libkrun-based VMs

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions