Skip to content
Search

Uvm32

lastmod 2025-12-15created 2025-12-152 edits

A tiny VM sandbox written in C, supporting Rust, C, and Zig apps

About

  • uvm32 is a minimal virtual machine sandbox for resource-constrained environments such as microcontrollers; it consists of a single C file and runs without dynamic memory allocation
  • Based on a RISC-V emulator, it runs bytecode apps written in C, Zig, Rust, and assembly, and its asynchronous design prevents the host from stalling
  • Can run with 3KB or less of flash and 1KB or less of RAM, and prioritizes safety so that faulty code does not crash the host
  • Provides various VM host examples and sample apps per language, so it can be integrated into diverse environments such as embedded systems, games, and plugins
  • Released under the MIT license, so it can be used freely in research, products, and embedded devices

uvm32 Overview

  • uvm32 is a dependency-free, lightweight virtual machine sandbox designed for microcontrollers and resource-constrained devices
    • Single C file structure, based on the C99 standard, asynchronous design, no dynamic memory
    • Runs in 3KB of flash / 1KB of RAM or less on STM32L0 (ARM Cortex-M0+)
  • Based on a RISC-V emulator, and includes a management interface and efficient code build tools

Main use cases

  • Replacing embedded scripting engines such as Lua, Duktape, and MicroPython
  • Isolating untrusted code through a sandbox environment
  • Enabling development in modern systems languages such as Rust and Zig
  • Minimizing multi-platform maintenance with the “Write once, run anywhere” principle

Key features

  • Includes bytecode examples written in C, Zig, Rust, and assembly
  • Non-blocking design, so misbehaving code does not stall the host
  • No assumptions about host I/O; simple and consistent execution model
  • Provides a safe, minimal FFI
  • Can run anything from small scripts to complex applications
  • Safety-first design; errors inside the VM do not damage the host
  • Based on a full CPU emulator, but not intended for hardware simulation

Comparison with alternatives

  • Smaller memory footprint than existing embedded scripting engines
  • Supports widely used languages such as C, Rust, and Zig
  • Easy integration with existing software
  • Supports various paradigms such as event-driven, polling, and multiprocessor
  • Robust against misbehaving VM code
  • On the other hand, it does not aim for direct FFI calls, maximum efficiency, a simple scripting experience, or a built-in standard library

Build and run (Docker)

  • Can be built with just a C compiler; a Docker environment is provided
    • Set up the environment with the make dockerbuild and make dockershell commands
    • After running make inside the Docker shell,
    • you can run ./hosts/host/host apps/helloworld/helloworld.bin
  • Check all options with the host -h command

License

  • Licensed under the MIT License
  • Can be used freely in research, products, embedded devices, etc.

See also

Favorite site

author Zer0 sitemap