Skip to content

Home › Pipeline

Security & Sandbox ​

Ouro runs untrusted guest code inside a pure-Luau register VM (v3–v14) with isolated environments, named safety presets, resource caps, cross-sandbox introspection isolation, and static bytecode verification.

text
Untrusted Source or Bytecode
  │
  ▼  1. Compile & Verify Gate
     mode = "text", allowDirectives = false, maxInstructions,
     Verifier bounds & metatable checks (rejects v100)
  │
  ▼  2. Environment Isolation
     inheritHost = false, library allowlist, locked metatables,
     isolated PCG32 RNG, cross-sandbox introspection filter
  │
  ▼  3. Runtime Budgets & Resource Caps
     instructionLimit, callLimit, timeout, interrupt,
     ResourceLimits & step-budgeted PatternMatch
  │
  ▼  Host Runtime (explicit capability wrappers only)

Hardened Sandbox Baseline ​

Start with Ouro.sandbox using preset = "strict" (or preset = "balanced" if guests need buffer, coroutine, and os). Call :fork() to create an isolated child environment per user or script.

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

local policy = Ouro.sandbox({
	preset = "strict",
	globals = {
		-- Expose only explicit capability functions, never raw Roblox services or host tables
		clamp = math.clamp,
	},
})

local untrustedSource = "return clamp(500, 0, 100)"
local guest = policy:fork()
local ok, result = guest:run(untrustedSource)
assert(ok and result == 100)

For one-shot untrusted strings, Ouro.run applies the same protection in a single call.

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

local ok, result = Ouro.run("return string.upper('safe')", {
	preset = "strict",
})
assert(ok and result == "SAFE")

Both Ouro.run and sandbox:run treat string inputs as mode = "text" by default, so user-submitted text is never interpreted as binary bytecode even if it begins with bytecode version header bytes. If you accept binary bytecode from an untrusted source, verify it first with Ouro.Bytecode.verify and pass mode = "binary" explicitly (or call Ouro.VM.loadBytecode).

Safety Presets Compared ​

Boundary"strict""balanced" (default)"trusted"
Standard librariesbase, bit32, math, string, table, utf8, vector"strict" + buffer, coroutine, osAll standard libraries
debug libraryOmittedOmittedIncluded (sandbox-scoped)
getfenv / setfenvIncluded (sandbox-scoped)Included (sandbox-scoped)Included (sandbox-scoped)
inheritHostfalsefalsefalse
allowDirectives (--!optimize, --!native, @native)false (clamped)false (clamped)true
instructionLimit250,0001,000,000Unlimited
callLimit64128VM ceiling (20,000)
timeout0.05s0.5sUnlimited
maxInstructions (compiler output)100,000500,0002,000,000
maxStringLength / maxBufferSize64 KiB1 MiBUnlimited
maxTableSize4,09665,536Unlimited
maxPatternLength / maxPatternSteps128 / 25,000256 / 100,000Unlimited
maxMemoryBytes4 MiB16 MiBUnlimited

Low-level Ouro.load does not apply a preset automatically; pass explicit limits or use Ouro.run / Ouro.sandbox for untrusted code.

Sandbox Boundaries & Threat Mitigations ​

  • Isolated Environments: Every sandbox and default Ouro.load creates a fresh pure-Luau environment (inheritHost = false). Even when inheritHost = true, script and loadstring are omitted and _G, getfenv, setfenv, debug, error, and xpcall remain sandboxed. Each :fork() overlay owns an independent 64-bit PCG32 math.random generator state so guests cannot observe or perturb host or sibling RNG sequences.
  • Cross-Sandbox Introspection Isolation: Guest getfenv, setfenv, debug.info, and debug.traceback filter out host frames and closures belonging to other sandboxes or contexts (including level-0 C-frame probes and both live and dead foreign coroutines). Guests cannot extract host functions, mutate another sandbox's environment, or read another sandbox's stack frames.
  • Locked Metatables & String Method Blocking: getmetatable("") returns "The metatable is locked" on both standalone Luau and Roblox. Writable and forked environments lock __metatable = "locked", and readOnly = true freezes the table (or returns a locked proxy under inheritHost = true). When "string" is omitted from libraries, VM dispatch also blocks string indexing and method calls (("abc"):upper(), ("").find).
  • CPU, Recursion & Memory DoS Controls: Combine instructionLimit, timeout, callLimit, and resourceLimits:
    • Standard-library constructors and formatters (string.rep, format, pack, char, upper, lower, reverse, sub, unpack, table.create, table.concat, table.move, table.clone, buffer.create, utf8.char, os.date, newproxy) pre-check output sizes and charge cumulative bytes against maxMemoryBytes.
    • Pattern APIs (string.find, match, gmatch, gsub) run through a step-budgeted Luau 0.748 matcher (maxPatternLength, maxPatternSteps) with streaming replacement length checks to stop catastrophic backtracking (ReDoS) and exponential gsub bombs.
    • Same-context pcall, xpcall, and coroutine.resume cannot swallow instructionLimit, timeout, interrupt, or maxMemoryBytes aborts.
    • allowDirectives = false prevents guest source from smuggling --!optimize 2, --!native, or @native to bypass compiler budgets, while CompileOptions.maxInstructions caps total emitted bytecode words.
  • Hostile Bytecode & IR Hardening: Binary bytecode (v3–v14) and in-memory ProtoModule tables pass static header, bounds, constant, import, jump-alignment, fastcall-target, upvalue-capture, and child-proto checks before any closure is instantiated. Experimental class bytecode (v100) is rejected cleanly. Verifier, BytecodeCodec, BytecodeDisassembler, and VM.loadProto reject metatable-tainted ProtoModule, proto, code, constant, and debug tables so hostile __index metamethods cannot execute during verification or deserialization.

Host API Hygiene Checklist ​

When exposing host functions in globals (especially in Roblox):

  1. Wrap host capabilities in thin Luau functions that validate argument types and ranges before calling Roblox engine APIs.
  2. Never expose raw mutable host tables, game, script, require, getfenv, or Instance references you do not want guests to traverse (.Parent, :GetDescendants()).
  3. Keep readOnly = true if scripts should not persist globals between runs, or :fork() a fresh child sandbox per execution.
  4. Set an explicit interrupt callback if you need host-driven cancellation between instruction chunks.

Supported Versions & Reporting a Vulnerability ​

Ouro tracks pinned official Luau releases (0.748 for v0.1.0). Security fixes target the latest 0.1.x release on main and the runtime-only dist branch.

To report a sandbox escape, verifier bypass, or DoS vulnerability, open a private GitHub Security Advisory with a minimal reproducer, expected behavior, and observed impact instead of filing a public issue.