3
0
Fork
You've already forked slua
1
No description
  • Lua 75.2%
  • Teal 23.8%
  • Shell 0.9%
  • Makefile 0.1%
Abigail Read 95f4ea9a54 Merge pull request 'Fix unnecessary log warnings' ( #1 ) from AbbyRead/slua:fix/undeclared-globals into main
Reviewed-on: #1
Merging this so that I can use the updated state as part of a skyblock_zero PR
2026年06月12日 11:58:48 +02:00
docs Remove loadstring from the default environment, because it assumes a lot about the environment 2026年04月25日 14:45:02 +02:00
tests Remove loadstring from the default environment, because it assumes a lot about the environment 2026年04月25日 14:45:02 +02:00
tl Fix unnecessary log warnings 2026年06月12日 02:54:07 -07:00
.luarc.json initial commit 2025年11月07日 19:03:58 +01:00
.stylua.toml initial commit 2025年11月07日 19:03:58 +01:00
env.lua Make xpcall less confusing 2026年05月17日 19:18:18 +02:00
import_tl.lua Fix small bug with concat 2026年01月05日 11:17:42 +01:00
init.lua Fix small bug with concat 2026年01月05日 11:17:42 +01:00
LICENSE readme reword 2025年11月13日 21:31:21 +01:00
misc.lua a lot of changes probably 2025年11月13日 21:17:25 +01:00
mod.conf Fix unnecessary log warnings 2026年06月12日 02:54:07 -07:00
README.md readme reword 2025年11月13日 21:31:21 +01:00
sandbox.lua Fix small bug with concat 2026年01月05日 11:17:42 +01:00
security.md add tl 2025年11月13日 21:25:57 +01:00
test.lua Fix small bug with concat 2026年01月05日 11:17:42 +01:00

slua - short for "Sandboxed Lua"

NOT YET FULLY FINISHED

  • missing more testing, documentation, possibly weighing the sandbox and async
  • and also i need to build something that uses it

A library to transpile input lua code into trivially sandboxable lua code, that doesn't need debug hooks for time limiting and replaces x .. y with some_func(x, y), allowing you to limit concatination too

The problems with usual lua sandboxing

  • String concatination cannot be reliably limited
    • This leads to bugs that can freeze a server
    • or it being limited with unreliable methods
  • In coroutine sandboxes, sometimes i want to automatically yield instead of throwing an error
    • Only lua C api can do this, not ideal in luanti
  • debug hooks are kinda awkward
    • Your code now becomes incompatible with tools like luacov
    • You have to disable JIT to use the most useful type of debug hook for sandboxing

What slua does to solve all of those

It modifies the inputted lua code. I don't think there is a better solution to this problem than doing that.

Slua will:

  • Replace concat expressions like x..y with __slua.concat(x, y)
  • Add a function before loop points
    while true do
    end
    
    Would turn into
    while true do
    __slua.limiting_function() end
    
  • Not allow you to declare certain locals
     local __slua = {} -- This table is also immutable when made as a global, so _G["__slu".."a"] = {} would throw an error at runtime
     local function f(__slua) end
    
    Would turn into
     local _not_allowed = {} -- It cannot make a syntax error in the code generation stage, so it just does this instead
     local function f(_not_allowed) end
    

Slua achieves this by using and modifying the tl (compiler for the teal language). When you are writing code to be sandboxed to slua, you are technically writing teal code, but all valid lua code is also valid teal code, so you don't have to concern yourself with this.

(削除) Slua could've been called Steal but that is a worse name (削除ここまで)