run_lua
Run a Lua 5.4 script against a document (sandboxed: io / os / app.fs / file loading and saving only inside allow_paths, everything else is denied; 128 MB memory, 10 s by default, timeout_seconds 1-120 raises the time and the instruction budget with it; source up to 16 MiB) as ONE undo step; if it...
This record as markdown: /tools/pixmith-mcp/run-lua.md
What run_lua does on Pixmith
AI agents invoke run_lua to trigger actions in Pixmith. What it does depends on the arguments the agent supplies, and its effects often reach beyond the immediate call: builds kicked off, notifications sent, workflows started.
| Parameter | Type | Required | Description |
|---|---|---|---|
doc | string | — | Document id (see doc_list); optional when only one document is open. |
code | string | — | Alias of `source`. |
path | string | — | A .lua file to run instead of `source`. |
script | string | — | Alias of `source`. |
source | string | — | Lua source code (up to 16 MiB). |
allow_paths | array | — | Folders (or files) the script may read and write with io / os / app.fs / Image{fromFile} / app.open / saveAs. Everything else is denied (there is nobody to ask) |
timeout_seconds | integer | — | Time limit in seconds, 1-120 (default 10). The instruction budget grows in proportion. |
Parameters from the server's own tool schema.
Why run_lua is rated High
run_lua triggers real processes with real consequences. An agent gone sideways doesn't fire it once. It starts dozens of builds, sends mass notifications, or burns through compute before anyone looks up.
Risk signalsAccepts freeform code/query input (script) · Accepts file system path (path) · Bulk/mass operation — affects multiple targets · Admin/system-level operation
Attacks that exploit this kind of access
The rule that runs run_lua safely
PolicyLayer is an MCP gateway: it sits between your AI agents and Pixmith, and checks every tool call against a rule you set before the call runs. Nothing changes on the server itself. For run_lua, this is the rule to start with:
run_lua stays usable, but rate-capped: a runaway agent can't fire it dozens of times a minute. Everything else on the server is denied unless you say otherwise.
The button opens the PolicyLayer dashboard: create your workspace, connect Pixmith, apply this rule, and every run_lua call is checked against it from then on.
Questions about run_lua
Run a Lua 5.4 script against a document (sandboxed: io / os / app.fs / file loading and saving only inside allow_paths, everything else is denied; 128 MB memory, 10 s by default, timeout_seconds 1-120 raises the time and the instruction budget with it; source up to 16 MiB) as ONE undo step; if it raises an error the document is left unchanged. The script sees sprite (pixels, layers, frames, cels, tags, slices, tilesets, selection, palette, user data), app and color; print() and app.alert() output is returned. NOTE: in Lua, layers/frames/tags are 1-based (layer 1 = bottom) while pixel coordinates and palette indices are 0-based; sprite.activeLayer/activeFrame are the document's active layer/frame. Files: with allow_paths (folders inside --root or an --allow-dir) a script can read images and sprites (Image{ fromFile=... }, Sprite{ fromFile=... }, app.open(path)) and write files; the script can see only ITS document plus the sprites it opens or creates itself (app.sprites lists exactly those): documents open in this server or in the Pixmith app are NOT visible to it, so doc_save (copy=true) the other document into an allowed folder and app.open it, or move pixels with clipboard / cel copy. Sprites a script creates or opens come back as new headless documents. Read the full API with the help tool (topic lua_api) or the pixmith://docs/lua-api resource. Give source (aliases: script, code) or a .lua path. It is categorised as a Execute tool in the Pixmith MCP Server, which means it can trigger actions or run processes. Use rate limits and argument validation.
run_lua accepts 7 parameters: doc, code, path, script, source, allow_paths, timeout_seconds. The full parameter table on this page comes from the server's own tool schema.
Register the Pixmith MCP server in PolicyLayer and add a rule for run_lua: allow, deny, rate-limit, or require approval. Point your MCP client at the PolicyLayer proxy URL and the rule is enforced on every call, before it reaches Pixmith. Nothing to install.
run_lua is a Execute tool with high risk. Execute tools should be rate-limited and have argument validation enabled.
Yes. Add a rate_limit block to the run_lua rule in your PolicyLayer policy. For example, setting max: 10 and window: 60 limits the tool to 10 calls per minute. Rate limits are tracked per agent session and reset automatically.
Set action: deny in the PolicyLayer policy for run_lua. The AI agent will receive a policy violation error and cannot call the tool. You can also include a reason field to explain why the tool is blocked.
run_lua is provided by the Pixmith MCP server (pixmith-mcp). PolicyLayer sits as a proxy in front of this server to enforce policies before tool calls reach the server.
More on Pixmith, and thousands of servers like it.
Across the catalogue