Concurrency is when code runs. Authority is what it can reach.
Emilua integrates both. Start with ordinary Lua control flow, add concurrent work when needed, and choose a memory and process boundary that matches the level of distrust.
Three execution primitives
| Primitive | Creates | Memory and authority | Typical job |
|---|---|---|---|
spawn() | Fiber in the current Lua VM | Shares VM memory; inherits the process’s authority | Concurrent I/O and background work |
spawn_vm() | Actor backed by another Lua VM, optionally in a child process | No shared Lua memory; explicit message passing and resource transfer | VM isolation, parallelism, and sandboxes |
system.spawn() | Operating-system process | Separate program; stdin, stdout, environment, and descriptors are configurable | GPG, system tools, and existing executables |
Processes created by system.spawn() use wait(). Fibers returned by spawn() use join(). The GPG example demonstrates why keeping those APIs distinct matters.
Waiting without callback-shaped code
An initiating I/O function suspends the current fiber, not the whole VM. The scheduler can run another ready fiber while the operating system completes the operation.
Sleepsort—small enough to expose the scheduling behavior
local sleep = require("time").sleep
local numbers = {8, 42, 38, 111, 2, 39, 1}
for _, n in pairs(numbers) do
spawn(function()
sleep(n / 100)
print(n)
end)
end
The output is 1, 2, 8, 38, 39, 42, 111. Sleepsort is a scheduling demonstration, not a recommended sorting algorithm. Scheduling is cooperative: a CPU-bound fiber must reach a suspension point rather than expect preemptive time slices.
Ambient authority versus explicit capability transfer
Ambient authority lets code name a resource and ask the operating system for it—for example, opening any path visible to the process. Explicit transfer instead gives a component a descriptor or channel chosen by its supervisor.
Easybox supplies a convenient privilege-dropping layer for subprocess actors. Its current policy and platform limitations still matter; a friendly Lua API is not proof that a policy is correct.
Code also has to cross the boundary
A sandbox without the application’s Lua source cannot run the requested worker. Emilua’s source_tree_cache pre-populates source modules before filesystem access is removed. The pipe and network examples package their worker source explicitly.
The compiled image demo uses emilua-genmain, which embeds its Lua module tree in the executable. Subprocess actors inherit that cache. emilua-genmods embeds the selected native modules, so require 'qt6' and Easybox remain available without granting a general filesystem.
Native-module transfer has OS-specific semantics. In particular, descriptor-based loading on Linux needs careful mount-namespace and Landlock treatment; the build and case-study pages state the verified setup rather than hiding it.
libc_service is compatibility, not enforcement
libc_service translates selected classic libc operations into requests to a supervisor. This lets existing libraries participate in an application-defined authority policy without rewriting every call site.
It is not a syscall firewall and does not itself block access. Combine it with real operating-system enforcement. Its master side also documents a no-multiplexing constraint: one slave thread is served at a time, which can limit parallelism when many ambient-authority calls occur.
The network-policy case study shows a complete request/reply policy rather than treating the module as a security slogan.
Qt has a threading model, too
The Qt binding runs the GUI on its own thread and suspends the calling Lua fiber while properties or operations cross that boundary. Signal callbacks are not ordinary fibers in which you can always suspend; the examples spawn a fiber for real work.
The image decoder deliberately uses qt.decode_image() only in the worker. The host uses qt.image_from_decode_result() to validate and map the returned framebuffer before display.