Compilation Targets: Unikernels
OCaml can compile to specialised unikernel targets through MirageOS, a library operating system that creates secure, single-purpose applications.
What are Unikernels?
Unikernels are specialised, single-purpose virtual machine images that bundle your application with only the minimal OS functionality it needs. Unlike traditional applications that run on general-purpose operating systems, unikernels:
- Include only the necessary OS components, resulting in tiny footprints (often just a few megabytes)
- Boot in milliseconds
- Have reduced attack surfaces due to minimal code
- Run directly on hypervisors or specialised monitor layers
MirageOS lets you write OCaml applications once and deploy them as unikernels to different virtualisation platforms.
Available Targets
MirageOS supports compilation to several unikernel backends:
Solo5 Targets
Solo5 is a sandboxed execution environment that provides multiple deployment options:
- hvt (Hardware Virtualized Tender) - Runs on KVM/Linux, bhyve/FreeBSD, and vmm/OpenBSD with minimal overhead
- spt (Sandboxed Process Tender) - Runs as a regular Unix process with seccomp sandboxing on Linux
- virtio - Runs on standard virtio-based hypervisors including QEMU/KVM, Google Compute Engine, and OpenStack
- muen - Runs on the Muen Separation Kernel
- xen - Runs on the Xen hypervisor as a paravirtualised guest (PVHv2 mode)
Unikraft Targets
Unikraft is a general Unikernel Development Kit that can be used as a MirageOS backend:
- unikraft-qemu - Runs on the QEMU virtual machine monitor
- unikraft-firecracker - Runs on the Firecracker virtual machine monitor
Unix
- unix - Runs as a standard Unix process (useful for development and testing)
Choosing a Target
Use Unix when you're developing and testing your unikernel locally.
Use hvt when you want lightweight virtualisation on Linux, FreeBSD, or OpenBSD with KVM, bhyve, or vmm.
Use virtio when deploying to cloud providers like Google Compute Engine, or standard KVM/QEMU setups.
Use spt when you want process-level isolation on Linux without full virtualisation.
Use Xen when deploying to Xen-based infrastructure or cloud providers that support Xen.
Use Unikraft targets when you want to use the Unikraft unikernel framework with QEMU or Firecracker.
Getting Started
To start building unikernels with OCaml, visit the MirageOS Getting Started Guide. The guide walks you through:
- Installing the MirageOS tooling
- Creating your first unikernel application
- Configuring and building for different targets
- Deploying your unikernel
Learn More
- Dune Manual: Executable Linking Modes - How to specify native, bytecode, or other compilation modes in Dune
- MirageOS Documentation - Comprehensive guides and tutorials
- MirageOS Blog - Updates and advanced topics
- Solo5 Documentation - Details on Solo5 targets and deployment
- MirageOS Examples - Sample unikernel applications to explore
Community
- Discuss OCaml Forums - Ask questions in the Ecosystem category
- MirageOS Mailing List - Development discussions
- IRC:
#mirageon Libera.Chat
Help Improve Our Documentation
All OCaml docs are open source. See something that's wrong or unclear? Submit a pull request.