Skip to content

Add NewSandboxedState to restrict standard libraries in Lua scripts - #721

Merged
gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:fix/lua-sandboxed-state
Nov 21, 2026
Merged

gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:fix/lua-sandboxed-state

Conversation

@gianlucam76

Copy link
Copy Markdown
Member

NewSandboxedState creates a Lua state with SkipOpenLibs and opens only the base, package, table, string, math and coroutine libraries. The os library only keeps time, date, clock and difftime. dofile and loadfile are removed and package.path is emptied so require cannot load Lua files from the host. Preloaded modules (json, strings, runes, sprig) keep working.

Callers can opt in by using this function instead of lua.NewState.

NewSandboxedState creates a Lua state with SkipOpenLibs and opens only the
base, package, table, string, math and coroutine libraries. The os library
only keeps time, date, clock and difftime. dofile and loadfile are removed
and package.path is emptied so require cannot load Lua files from the host.
Preloaded modules (json, strings, runes, sprig) keep working.

Callers can opt in by using this function instead of lua.NewState.
@gianlucam76
gianlucam76 merged commit 4c6efa5 into projectsveltos:main Nov 21, 2026
4 checks passed
@gianlucam76
gianlucam76 deleted the fix/lua-sandboxed-state branch November 21, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant