Expand description
The embedded Luau VM, and the sandbox around it.
Everything here follows Roblox’s published guidance for embedding Luau with untrusted code, because Roblox runs millions of hostile scripts on this exact VM and has written down what it took.
Library globals are read-only at the VM level. sandbox(true) marks the
library tables, the string metatable, and the global table readonly in a way
that blocks rawset and setmetatable too, not just assignment. PUC Lua
has no equivalent primitive, which is one reason yk chose Luau.
The unsafe libraries are never loaded. Seven libraries are requested:
coroutine, table, string, math, utf8, bit32, and buffer, so
os, io, package, debug, and ffi do not exist. That is a whitelist:
a blacklist leaves package.loadlib reachable, which is the documented
escape. os is not on the list: Luau’s os registers exactly clock,
date, difftime, and time, with no execute, but the requirement is a
whitelist with no dangerous library in it and os is on the list. It comes
out.
Bytecode is never loaded. set_mode("t") refuses binary chunks, which is
the escape Lua workshop documented for 5.1.
A runaway script is stopped by an instruction limit. The interrupt
fires at any function call or loop iteration, and a counter bounds how many
firings one execution may have. while true do end returns an error
rather than wedging the agent. This is the other reason for Luau: mlua
exposes no equivalent on PUC Lua.
Memory is capped. The interrupt does not stop a script that allocates without calling anything.
The process gateway is runner. An extension that needs a file, a
network service, or another binary asks the host to run a process. The
child is a separate OS process: isolated by the kernel, killable by the
host, and unable to touch agent memory. There is no FFI, no ffi library,
and no native module loading, in any dialect, ever.
What this is not: a memory-isolated process. There is one heap per
lua_State, not per script. The session survives a crash because it is
append-only.
Structs§
- Deny
Host - A host that refuses everything, for tests and for running with no network.
- Execution
Budget - The per-execution budget, shared between the registry and its tools.
- Extension
Sources - Where extensions are loaded from, and whether they may run.
- Hook
- A hook an extension registered through
on_tool_call. - Hook
Guarded Tool - Any tool wrapped so an extension’s
on_tool_callhooks see it. - Http
Response - What an HTTP POST came back with.
- Loaded
Script - A loaded script, for the startup message.
- LuaTool
- A Lua function exposed to the loop as a tool.
- Registry
- The embedded VM and everything registered against it.
- Tool
Info - What an extension declared. Kept whole so the tool can borrow its callback.
Constants§
- TOOL_
TIMEOUT - The deadline a single execution gets by default.
Traits§
- Host
- What an extension can ask the host to do.
Functions§
- extension_
sources - The default
extension_sourcesfor a run inproject_root. - is_
builtin - Whether
nameis one of the built-in tools. - session_
dir - Where extensions the model wrote live, inside a project.
- user_
dir - The conventional user directory for extensions.