Skip to main content

Crate yk_lua

Crate yk_lua 

Source
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§

DenyHost
A host that refuses everything, for tests and for running with no network.
ExecutionBudget
The per-execution budget, shared between the registry and its tools.
ExtensionSources
Where extensions are loaded from, and whether they may run.
Hook
A hook an extension registered through on_tool_call.
HookGuardedTool
Any tool wrapped so an extension’s on_tool_call hooks see it.
HttpResponse
What an HTTP POST came back with.
LoadedScript
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.
ToolInfo
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_sources for a run in project_root.
is_builtin
Whether name is 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.