40 lines · 940 B · Lua
RawDownload
---@diagnostic disable: undefined-global -- Create a sandbox environmentlocal sandbox = {} -- Allow access to standard libraries (safe subset)sandbox.string = stringsandbox.table = tablesandbox.math = mathsandbox.print = sb_printsandbox.type = typesandbox.tostring = tostringsandbox.tonumber = tonumbersandbox.pairs = pairssandbox.ipairs = ipairssandbox.search = search -- Create a sandboxed version of LuaFileIOlocal io = {} -- File functionsio.open = sb_io_open -- Add the sandboxed io library to the sandbox environmentsandbox.io = io  -- Load the script with the sandbox environmentlocal user_script_fn, err = load(user_script, nil, "t", sandbox) if not user_script_fn then  error("Failed to load user script: " .. tostring(err))end -- Execute the user script within the sandboxlocal success, result = pcall(user_script_fn) if not success then  error("Error executing user script: " .. tostring(result))end