VM
Pure-Luau Luau 0.748 register VM with isolated environments, execution budgets, and debug hooks.
Types
ProtoModule type
type ProtoModule = {
version: number,
typesversion: number,
strings: { string },
protos: { Proto },
mainid: number,
userdataTypes: { string }?,
}In-memory decoded bytecode module produced by Bytecode.deserialize and Compiler.compileProto.
LoadOptions type
type LoadOptions = {
name: string?, -- chunk name for stack traces (`"=chunk"` for binary inputs, `[string "..."]` for text)
env: { [any]: any }?, -- custom global environment (defaults to a fresh isolated `VM.createEnvironment()`)
compile: CompileOptions?, -- compiler options when loading text source chunks
decoder: BytecodeDecoder?, -- reverses a custom `CompileOptions.encoder` on binary bytecode
mode: LoadMode?, -- `"text"`, `"binary"`, or `"auto"` header sniffing (defaults `"text"` for strings, `"binary"` for buffers)
timeout: number?, -- lazy wall-clock deadline in seconds (`os.clock()`) started on first invocation
instructionLimit: number?, -- maximum VM instructions executed before aborting
callLimit: number?, -- maximum active guest call frames across nested calls and coroutines
interruptInterval: number?, -- instruction interval between `interrupt` and `timeout` checks (default `4,096`)
interrupt: (() -> boolean?)?, -- periodic callback; return `false`, yield, or error to abort execution
getGlobal: ((name: string, env: { [any]: any }) -> any)?, -- intercepts global reads (`GETGLOBAL`, unresolved `GETIMPORT`, `_G[k]`)
setGlobal: ((name: string, value: any, env: { [any]: any }) -> ())?, -- intercepts global writes (`SETGLOBAL`, `_G[k] = v`)
safeEnv: boolean?, -- preserve fast paths on unmodified built-in roots present in `env` alongside `getGlobal`
resourceLimits: (ResourceLimits | false)?, -- overrides `env` resource caps (`false` disables caps inherited from `env`)
onCall: ((info: DebugFrameInfo) -> ())?, -- fires when entering a VM closure frame
onReturn: ((info: DebugFrameInfo) -> ())?, -- fires before exiting a VM closure frame
onLine: ((line: number, info: DebugFrameInfo) -> ())?, -- fires when execution advances to a different source line
onBreak: ((line: number, info: DebugFrameInfo) -> ())?, -- fires on `LOP_BREAK` instructions
}Execution environment, resource budget, global hook, and debug hook options for Ouro.load.
SandboxPreset type
type SandboxPreset = "strict" | "balanced" | "trusted"Named safety preset for Ouro.sandbox and Ouro.run.
SandboxPresetConfig type
type SandboxPresetConfig = {
libraries: { string }?, -- stdlib allowlist (`nil` enables all standard libraries)
inheritHost: boolean, -- inherit non-standard host or Roblox globals
allowDirectives: boolean, -- allow `--!optimize`, `--!native`, and `@native` escalation
instructionLimit: number?, -- default VM instruction cap (`nil` for unlimited)
callLimit: number?, -- default active call-frame cap (`nil` for default VM ceiling)
timeout: number?, -- default wall-clock deadline in seconds (`nil` for unlimited)
maxInstructions: number?, -- default compiler bytecode size cap (`nil` for compiler default)
resourceLimits: ResourceLimits?, -- default stdlib, pattern, and memory caps (`nil` for zero wrapper overhead)
}Transparent policy defaults backing each named SandboxPreset in Ouro.PRESETS.
SandboxOptions type
type SandboxOptions = {
preset: SandboxPreset?, -- safety preset: `"strict"`, `"balanced"` (default), or `"trusted"`
globals: { [string]: any }?, -- custom globals and host APIs exposed read-only in the sandbox base environment
libraries: { string }?, -- stdlib allowlist overriding the preset (`"base"`, `"bit32"`, `"buffer"`, `"coroutine"`, `"debug"`, `"math"`, `"os"`, `"string"`, `"table"`, `"utf8"`, `"vector"`)
inheritHost: boolean?, -- inherit non-standard host or Roblox globals (`script` and `loadstring` remain excluded)
readOnly: boolean?, -- lock the sandbox environment read-only so guest scripts cannot assign globals (default `false`)
instructionLimit: (number | false)?, -- maximum VM instructions before aborting (`false` disables preset limit)
callLimit: (number | false)?, -- maximum active guest call frames (`false` disables preset limit)
timeout: (number | false)?, -- wall-clock deadline in seconds (`false` disables preset limit)
interruptInterval: number?, -- instruction interval between `interrupt` and `timeout` checks (default `4,096`)
interrupt: (() -> boolean?)?, -- periodic hook; return `false`, yield, or error to abort execution
resourceLimits: (ResourceLimits | false)?, -- overrides preset stdlib, pattern, and memory caps (`false` disables preset caps)
compile: CompileOptions?, -- compiler defaults merged with `allowDirectives` and preset `maxInstructions`
allowDirectives: boolean?, -- explicit `--!optimize`/`--!native`/`@native` escalation policy overriding the preset
getGlobal: ((name: string, env: { [any]: any }) -> any)?, -- intercepts global reads
setGlobal: ((name: string, value: any, env: { [any]: any }) -> ())?, -- intercepts global writes
safeEnv: boolean?, -- preserve fast paths on unmodified built-in roots alongside `getGlobal`
onCall: ((info: DebugFrameInfo) -> ())?, -- fires when entering a VM closure frame
onReturn: ((info: DebugFrameInfo) -> ())?, -- fires before exiting a VM closure frame
onLine: ((line: number, info: DebugFrameInfo) -> ())?, -- fires when execution advances to a new source line
onBreak: ((line: number, info: DebugFrameInfo) -> ())?, -- fires on `LOP_BREAK` instructions
}Configuration options for Ouro.sandbox and Sandbox:fork.
RunOptions type
type RunOptions = {
name: string?, -- chunk name for stack traces
mode: LoadMode?, -- `"text"`, `"binary"`, or `"auto"` (defaults `"text"` for strings, `"binary"` for buffers)
decoder: BytecodeDecoder?, -- reverses a custom `CompileOptions.encoder` on binary bytecode
preset: SandboxPreset?, -- safety preset: `"strict"`, `"balanced"` (default), or `"trusted"`
globals: { [string]: any }?, -- custom globals and host APIs exposed in the sandbox environment
libraries: { string }?, -- stdlib allowlist overriding the preset
inheritHost: boolean?, -- inherit non-standard host or Roblox globals (`script` and `loadstring` remain excluded)
readOnly: boolean?, -- lock the environment read-only so guest scripts cannot assign globals
instructionLimit: (number | false)?, -- maximum VM instructions before aborting (`false` disables preset limit)
callLimit: (number | false)?, -- maximum active guest call frames (`false` disables preset limit)
timeout: (number | false)?, -- wall-clock deadline in seconds (`false` disables preset limit)
interruptInterval: number?, -- instruction interval between `interrupt` and `timeout` checks (default `4,096`)
interrupt: (() -> boolean?)?, -- periodic hook; return `false`, yield, or error to abort execution
resourceLimits: (ResourceLimits | false)?, -- overrides preset stdlib, pattern, and memory caps (`false` disables preset caps)
compile: CompileOptions?, -- compiler defaults merged with `allowDirectives` and preset `maxInstructions`
allowDirectives: boolean?, -- explicit `--!optimize`/`--!native`/`@native` escalation policy overriding the preset
getGlobal: ((name: string, env: { [any]: any }) -> any)?, -- intercepts global reads
setGlobal: ((name: string, value: any, env: { [any]: any }) -> ())?, -- intercepts global writes
safeEnv: boolean?, -- preserve fast paths on unmodified built-in roots alongside `getGlobal`
onCall: ((info: DebugFrameInfo) -> ())?, -- fires when entering a VM closure frame
onReturn: ((info: DebugFrameInfo) -> ())?, -- fires before exiting a VM closure frame
onLine: ((line: number, info: DebugFrameInfo) -> ())?, -- fires when execution advances to a new source line
onBreak: ((line: number, info: DebugFrameInfo) -> ())?, -- fires on `LOP_BREAK` instructions
}Configuration options for one-shot safe execution via Ouro.run.
SandboxHandle type
type SandboxHandle = {
preset: SandboxPreset, -- active safety preset (`"strict"`, `"balanced"`, or `"trusted"`)
env: { [any]: any }, -- isolated global environment table owned by this sandbox
readOnly: boolean, -- true when guest global writes and `Sandbox:set` are blocked
allowDirectives: boolean, -- true when `--!optimize`/`--!native`/`@native` escalation is permitted
run: (self: Sandbox, chunk: string | buffer | ProtoModule, ...any) -> (boolean, ...any),
load: (
self: Sandbox,
chunk: string | buffer | ProtoModule,
options: SandboxLoadOptions?
) -> (((...any) -> ...any)?, string?),
compile: (self: Sandbox, source: string | ParseResult, options: CompileOptions?) -> (string?, string?),
fork: (self: Sandbox, overrides: SandboxOptions?) -> Sandbox,
reset: (self: Sandbox) -> (),
get: (self: Sandbox, name: string) -> any,
set: (self: Sandbox, name: string, value: any) -> (),
}Reusable sandbox policy and isolated execution environment created by Ouro.sandbox.
Properties
PRESETS Read Only
VM.PRESETS: { [SandboxPreset]: SandboxPresetConfig }Frozen definitions of the built-in sandbox safety presets (strict, balanced, trusted).
DEFAULT_RESOURCE_LIMITS Re-export
VM.DEFAULT_RESOURCE_LIMITSBaseline resource limits used by the "balanced" sandbox preset and available for opt-in LoadOptions.resourceLimits.
createEnvironment Re-export
VM.createEnvironmentBuilds an isolated VM global environment table with pure Luau standard libraries or optional host fallbacks.
forkEnvironment Re-export
VM.forkEnvironmentCreates a writable per-chunk overlay table backed read-only by baseEnv with isolated PCG32 RNG state.
traceback Re-export
VM.tracebackFormats a guest VM stack trace matching upstream luaL_traceback.
getCoverage Re-export
VM.getCoverageReturns per-proto line execution counts for closures compiled with coverageLevel 1 or 2.
cloneFunction Re-export
VM.cloneFunctionClones a VM closure sharing upvalue references with optional new environment and load overrides.
getUpvalues Re-export
VM.getUpvaluesInspects captured upvalues (1-based) on a VM closure.
setUpvalue Re-export
VM.setUpvalueMutates an open or closed upvalue slot (1-based) on a VM closure.
resetBudget Re-export
VM.resetBudgetResets the instruction counter, memory counter, and lazy timeout timer for the module context owning fn.
Functions
run
VM.run(chunk: string | buffer | ProtoModule, options: RunOptions?, ...: any): (boolean, ...any)Executes source, binary bytecode, or a ProtoModule inside a fresh safe-by-default sandbox, returning (ok, ...resultsOrErr).
sandbox
VM.sandbox(options: SandboxOptions?): SandboxHandleCreates a reusable Sandbox policy and isolated environment handle (:run, :load, :compile, :fork, :reset, :get, :set).
load
VM.load(chunk: string | buffer | ProtoModule, options: LoadOptions?): (((...any) -> ...any)?, string?)Compiles or deserializes a Luau chunk (source, binary bytecode, or ProtoModule) into a callable sandboxed closure.
loadBytecode
VM.loadBytecode(bytecode: string | buffer, options: LoadOptions?): (((...any) -> ...any)?, string?)Deserializes binary Luau bytecode (string or buffer) and loads it into a callable closure without invoking the compiler.
loadProto
VM.loadProto(protoModule: ProtoModule, options: LoadOptions?): (((...any) -> ...any)?, string?)Validates and instantiates a callable closure from an in-memory ProtoModule.