kohltastrophe/ouro

Self-hosted Luau 0.748 lexer, parser, bytecode compiler, and sandboxed register VM in pure Luau.

Ouro Docs Benchmarks Download Discord




Parse. Compile. Execute.

Ouro is a self-hosted Luau 0.748 lexer, lossless parser, bytecode compiler, and sandboxed register VM written in pure --!strict Luau. It runs on Roblox and standalone Luau without FFI, loadstring, or native code-loading services.

CI Coverage Benchmarks Upstream Luau 0.748 License GitHub Release


Execute in a sandbox

Run untrusted Luau code safely in a few lines with Ouro.run or build a reusable policy with Ouro.sandbox. Both default to the "balanced" safety preset (isolated pure-Luau libraries, instruction/call/time budgets, string/table/pattern/memory limits, and clamped compiler directives) and return pcall-style (ok, ...resultsOrErr) tuples so guest errors never crash the host.

--!strict
local Ouro = require("./ouro")

-- One-shot safe execution (isolated env + default budgets & resource limits)
local ok, result = Ouro.run("local x = ...; return x * 2 + 2", {
	preset = "strict",
}, 20)
assert(ok and result == 42)

-- Reusable policy with host APIs and per-script isolated forks
local base = Ouro.sandbox({
	preset = "strict",
	globals = { clamp = math.clamp },
})
local playerEnv = base:fork()
local runOk, value = playerEnv:run("return clamp(150, 0, 100)")
assert(runOk and value == 100)

For zero-overhead execution of trusted or pre-budgeted code, Ouro.load, Ouro.VM.loadBytecode, and Ouro.VM.loadProto run on the unguarded @native dispatch loop unless budgets or hooks are explicitly configured. See Sandboxed VM, Security & Sandbox, and the Cookbook.


Parse without loss

Ouro.parse lowers Luau syntax, type annotations, and .d.luau declarations into flat numeric arenas with zero-based half-open byte offsets. Slice node source with parsed:text(nodeId), format human-readable diagnostics with parsed:formatDiagnostics(), enable lossless = true for exact reconstruct() output, or materialize nested tables with Ouro.Ast.toTables.

--!strict
local Ouro = require("./ouro")

local source = "-- keep comments\nlocal x: number = 20 + 22\nreturn x"
local parsed = Ouro.parse(source, { profile = "studio", lossless = true })

if parsed.status == "ok" then
	assert(parsed:kindName(parsed.root) == "AstStatBlock")
	assert(parsed:reconstruct() == source)
else
	print(parsed:formatDiagnostics())
end

See Parsing & AST for Profiles, parseExpression, parseType, and cooperative yielding with Ouro.newContext.


Compile to Luau bytecode
--!strict
local Ouro = require("./ouro")

local bytecode = assert(Ouro.compile("local a, b = ...\nreturn a * b + 2", {
	optimizationLevel = 2,
}))

local listing = assert(Ouro.Bytecode.disassemble(bytecode))
assert(#listing > 0)

Ouro.compile emits binary Luau bytecode (v14 default, v100 for classes) across optimization levels 0, 1, and 2, matching upstream constant folding, builtin fastcalls, inlining, and loop specialization. Ouro.Bytecode includes serialize, deserialize, verify (v3–v14), and disassemble, all returning uniform (value?, err?) tuples. See Compiling & Bytecode.


Run fast in pure Luau Ouro vs Fiu vs LuauCeption geometric-mean benchmark comparison

Ouro pairs dual @native fast and guarded VM dispatch loops with lazy submodule loading: root require loads types and a thin facade, deferring Parser, Compiler, Bytecode, and VM until accessed. The Benchmarks workflow verifies host parity across every workload before timing --codegen -O2, -O2 interpreter execution, O2 compilation, and cold startup against Fiu and LuauCeption. See Benchmarks for full charts and methodology.


Pipeline & Entrypoint Guide

Luau Source ──▶ Ouro.parse ──▶ ParseResult (Flat Arena)
                                      │
                                      ▼
                               Ouro.compile ──▶ Binary Bytecode (v3–v14) / ProtoModule
                                                       │
                                                       ▼
                               Ouro.Bytecode.verify ──▶ Ouro.run / Ouro.sandbox / Ouro.load
GoalRecommended APIReturn Contract
Run untrusted text once with safe defaultsOuro.run(ok, ...resultsOrErr)
Run many scripts under a shared policy & host APIsOuro.sandbox (:fork, :run, :load, :reset)Sandbox handle
Load source or bytecode on the fast unguarded loopOuro.load(fn?, err?)
Execute precompiled bytecode without loading the compilerOuro.VM.loadBytecode / loadProto(fn?, err?)
Compile source or ParseResult to binary bytecodeOuro.compile / Ouro.compileResult(bytecode?, err?) / CompileResult
Parse scripts, expressions, types, or .d.luau filesOuro.parse / parseExpression / parseTypeParseResult
Verify, decode, serialize, or disassemble bytecodeOuro.Bytecode(okOrValue?, err?)

Batteries Included

  • Safe-by-default sandboxes & presets: Choose "strict", "balanced", or "trusted" in Ouro.PRESETS, expose custom host globals, fork isolated per-script overlays with independent PCG32 math.random state, and reset budgets between runs via Ouro.sandbox.
  • Arena parser & lossless reconstruction: Parse scripts, expressions, type packs, and .d.luau files, slice node text with :text(), render caret diagnostics with :formatDiagnostics(), preserve exact bytes with lossless = true, and traverse arenas via Ouro.parse and Ouro.Ast.
  • Grammar profiles & strict flags: Switch between upstream, studio, and experimental presets or toggle individual syntax flags via Ouro.Profiles.
  • Full O0–O2 bytecode compiler: Inline functions, fold builtins and constants, emit vector, native, and usercall fastcalls, enforce maxInstructions and allowDirectives, and verify or inspect bytecode (v3–v14, v100 classes) through Ouro.Compiler and Ouro.Bytecode.
  • Isolated register VM & tooling hooks: Enforce instruction, call, timeout, string, table, buffer, pattern-step, and memory caps, intercept global reads and writes, collect line coverage, and attach stack/upvalue debuggers via Ouro.VM.

Installation

Install kohltastrophe/ouro with Wally or pesde (pesde add kohltastrophe/ouro), download Ouro.rbxm or Ouro-<version>-package.zip from GitHub Releases and place the module in ReplicatedStorage, sync src directly with Rojo, or pull the runtime-only dist branch via git subtree. Standalone Luau callers can require the repository root directly (require("./ouro")).

Read Getting Started, browse the Cookbook, or open the API Reference.

Acknowledgments

Ouro translates lexer, parser, compiler, bytecode, and VM algorithms and confusable mappings from official Luau, pinned to 0.748 (3d91c9d) in UPSTREAM.json. Arena storage, public APIs, the lossless lexical tape, sandbox presets, and coroutine checkpointing are adaptations for this pure-Luau port.

Sponsors

Ouro is free and MIT-licensed. If Ouro is useful to you or your team, you can support its development through GitHub Sponsors or Ko-fi.

GitHub Sponsors  Ko-fi Sponsors