Skip to main content

Description

Executes Luau code in edit mode (not during play mode). Captures print, warn, and error output, and returns the result of the execution. Useful for quick scripts, debugging, and automation tasks.

Endpoint

execute_luau

Parameters

code
string
required
The Luau code to execute

Response

ok
boolean
Returns true if the code executed successfully
result
any
The return value of the executed code, serialized to JSON-compatible format
output
array
Array of captured output strings from print, warn, and error calls
error
string
Error message if compilation or execution failed

Output Format

Captured output is prefixed with:
  • [OUTPUT] - from print() calls
  • [WARNING] - from warn() calls
  • [ERROR] - from error() calls

Examples

Simple calculation

{
  "code": "return 2 + 2"
}
Response:
{
  "ok": true,
  "result": 4,
  "output": []
}

Create a part

{
  "code": "local part = Instance.new('Part')\npart.Parent = workspace\npart.Position = Vector3.new(0, 10, 0)\nreturn part.Name"
}
Response:
{
  "ok": true,
  "result": "Part",
  "output": []
}

With print output

{
  "code": "print('Starting...')\nlocal sum = 0\nfor i = 1, 10 do sum = sum + i end\nprint('Done')\nreturn sum"
}
Response:
{
  "ok": true,
  "result": 55,
  "output": [
    "[OUTPUT] Starting...",
    "[OUTPUT] Done"
  ]
}

Return table data

{
  "code": "return { players = 5, maxPlayers = 10, gameMode = 'Deathmatch' }"
}
Response:
{
  "ok": true,
  "result": {
    "players": 5,
    "maxPlayers": 10,
    "gameMode": "Deathmatch"
  },
  "output": []
}

Compilation error

{
  "code": "local x = "
}
Response:
{
  "error": "Compile error: ..."
}

Runtime error

{
  "code": "error('Something went wrong')"
}
Response:
{
  "error": "Runtime error: Something went wrong",
  "output": ["[ERROR] Something went wrong"]
}

Build docs developers (and LLMs) love