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.
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.
--!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.
--!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 libraries | base, bit32, math, string, table, utf8, vector | "strict" + buffer, coroutine, os | All standard libraries |
debug library | Omitted | Omitted | Included (sandbox-scoped) |
getfenv / setfenv | Included (sandbox-scoped) | Included (sandbox-scoped) | Included (sandbox-scoped) |
inheritHost | false | false | false |
allowDirectives (--!optimize, --!native, @native) | false (clamped) | false (clamped) | true |
instructionLimit | 250,000 | 1,000,000 | Unlimited |
callLimit | 64 | 128 | VM ceiling (20,000) |
timeout | 0.05s | 0.5s | Unlimited |
maxInstructions (compiler output) | 100,000 | 500,000 | 2,000,000 |
maxStringLength / maxBufferSize | 64 KiB | 1 MiB | Unlimited |
maxTableSize | 4,096 | 65,536 | Unlimited |
maxPatternLength / maxPatternSteps | 128 / 25,000 | 256 / 100,000 | Unlimited |
maxMemoryBytes | 4 MiB | 16 MiB | Unlimited |
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.loadcreates a fresh pure-Luau environment (inheritHost = false). Even wheninheritHost = true,scriptandloadstringare omitted and_G,getfenv,setfenv,debug,error, andxpcallremain sandboxed. Each:fork()overlay owns an independent64-bitPCG32math.randomgenerator state so guests cannot observe or perturb host or sibling RNG sequences. - Cross-Sandbox Introspection Isolation: Guest
getfenv,setfenv,debug.info, anddebug.tracebackfilter out host frames and closures belonging to other sandboxes or contexts (including level-0C-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", andreadOnly = truefreezes the table (or returns a locked proxy underinheritHost = true). When"string"is omitted fromlibraries, VM dispatch also blocks string indexing and method calls (("abc"):upper(),("").find). - CPU, Recursion & Memory DoS Controls: Combine
instructionLimit,timeout,callLimit, andresourceLimits:- 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 againstmaxMemoryBytes. - Pattern APIs (
string.find,match,gmatch,gsub) run through a step-budgeted Luau0.748matcher (maxPatternLength,maxPatternSteps) with streaming replacement length checks to stop catastrophic backtracking (ReDoS) and exponentialgsubbombs. - Same-context
pcall,xpcall, andcoroutine.resumecannot swallowinstructionLimit,timeout,interrupt, ormaxMemoryBytesaborts. allowDirectives = falseprevents guest source from smuggling--!optimize 2,--!native, or@nativeto bypass compiler budgets, whileCompileOptions.maxInstructionscaps total emitted bytecode words.
- Standard-library constructors and formatters (
- Hostile Bytecode & IR Hardening: Binary bytecode (
v3–v14) and in-memoryProtoModuletables 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, andVM.loadProtoreject metatable-taintedProtoModule, proto, code, constant, and debug tables so hostile__indexmetamethods cannot execute during verification or deserialization.
Host API Hygiene Checklist
When exposing host functions in globals (especially in Roblox):
- Wrap host capabilities in thin Luau functions that validate argument types and ranges before calling Roblox engine APIs.
- Never expose raw mutable host tables,
game,script,require,getfenv, orInstancereferences you do not want guests to traverse (.Parent,:GetDescendants()). - Keep
readOnly = trueif scripts should not persist globals between runs, or:fork()a fresh child sandbox per execution. - Set an explicit
interruptcallback 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.