local sandbox ={}-- Define a print function in the sandbox
sandbox.print =function(s)
returnprint("[Sandbox] ".. s)
endlocal sandboxedCode =function()
print("Hello")
string.format("%s", "error please")
end-- change environment for sandboxedCode to the sandbox tablesetfenv(sandboxedCode, sandbox)
sandboxedCode()
Output:
[Sandbox] Hello
Script:11: attempt to index global 'string' (a nil value)