Lua Sandbox
Lua 5.3 Ready
▼
YOUR IDEAS. IN CODE.

A little Lua. Endless possibilities.

Write, run, and explore — right in your browser.

Files saved on this device
×
>
Active Environment Globals (Lua 5.3) 0 custom items
Run some Lua code defining global variables or tables to inspect them here.

Lua Sandbox: Write and Run Lua Code Online

Lua Sandbox lets you write and run Lua 5.3 code directly in your browser. Enter a script or choose an example, run it, and review the console output and any errors. This edit-run-check workflow helps you understand how variables, loops, functions, and tables behave. You can also inspect global variables or use canvas drawing helpers to explore visual output.

How to Use This App

  • Enter Lua code in the editor or choose a built-in example from the template menu.
  • Click Run or press Ctrl+Enter to execute your script.
  • Review the console output and use error-line links to locate problems.
  • Inspect custom global variables and tables in the inspector, or view drawing results in the Canvas tab.
  • Modify your code and run it again to compare the results.
  • Download your script as a Lua file or click Share to copy a link to your code.

Examples and Use Cases

  • Practice loops: Enter for i = 1, 5 do print(i * i) end and run it. The console displays 1, 4, 9, 16, and 25 on separate lines.
  • Inspect a Lua table: Run player = {name = "Alex", score = 100}. Open the global-variable inspector to examine the player table and its values. Use a global assignment here because local variables do not appear in this inspector.
  • Test an expression: Enter math.sqrt(144) in the interactive console to get 12 without creating a full script.
  • Explore canvas drawing: Load a drawing example and run it to see the result in the Canvas tab. Change its coordinates or colours, rerun it, and save the resulting image as a PNG.
  • Share a coding exercise: Write a function that converts Celsius to Fahrenheit using c * 9 / 5 + 32. Test it with 0 and 100 to get 32 and 212, then use Share to copy a link to your snippet.

Helpful Details

Understand Variable Scope and Execution State

The inspector shows custom global variables and tables after a successful run. Variables declared with local do not appear there. Prefer local variables for ordinary scripts, and use print to check their values.

Isolated mode starts each execution with a fresh Lua state. Persistent mode keeps globals between executions, which is useful for interactive experiments but can make results depend on earlier commands.

Common Lua Mistakes to Check

  • Assignment versus comparison: Use = to assign a value and == to compare values. Lua uses ~= for “not equal.”
  • Joining text: Use .. to concatenate strings, such as "Hello, " .. "Alex".
  • Table indexing: List-style table entries normally start at index 1.
  • Conditions: Only false and nil are false in Lua. The number 0 and an empty string both count as true.
  • Block endings: Close functions, conditional blocks, and for or while loops with end. A repeat loop closes with until and a condition.

Sharing and Runtime Limitations

A shared link contains the current editor’s code in its URL fragment. Anyone with that link can read the snippet, so remove passwords, tokens, and personal information before sharing. Download important scripts as Lua files to keep a separate copy.

This playground runs Lua 5.3 through a browser runtime. Scripts that depend on native modules, operating-system commands, or another application’s APIs may not work here. The canvas helpers belong to this playground and are not part of standard Lua.

Frequently Asked Questions

Do I need to install Lua to use Lua Sandbox?

No. Lua Sandbox runs Lua 5.3 code directly in your browser. Enter your code or choose an example, then click Run to view the results.

What is the difference between isolated and persistent mode?

Isolated mode starts each execution with a fresh Lua state. Persistent mode keeps global variables between executions, allowing later scripts or console commands to use values created earlier.

Why is my variable missing from the inspector?

The inspector displays custom global variables and tables after a successful run. Variables declared with local do not appear there. Use print to display local values in the console.

Can I import, download, and share Lua scripts?

Yes. You can import a Lua file or drag it onto the editor, download the current script as a .lua file, and use Share to copy a link containing the current editor’s code. Anyone with that link can read the snippet.

Can I run Roblox or Love2D scripts in Lua Sandbox?

Scripts that depend on Roblox or Love2D APIs will not run unchanged because those environments are not included. You can test compatible Lua logic that does not rely on their features. Roblox also uses Luau, which differs from Lua 5.3.

Can Lua Sandbox create graphics?

Yes. The app provides canvas drawing helpers and drawing examples. Run code that uses these helpers to view graphics in the Canvas tab, then save the canvas as a PNG. These helpers are specific to this playground and are not part of standard Lua.