How can I sandbox builtin functions roblox has like loadstring
or rawget
? I’m not trying to create a script builder but I believe it’s fun and good knowledge to have. I apologize, I don’t have any code to show because I don’t know where to start. I’m not asking for a handout but an article our guidance would help a lot.
1 Like
I don’t recommend this, since it can disable some of Luau’s optimizations, but you can use setfenv
on a function to set its environment.
local env = { }
local function f()
print(1)
end
setfenv(f, env)
f() -- attempt to call a nil value
Also, rawget
isn’t inherently dangerous, not sure why you want to sandbox it
1 Like
Thank you a lot, I’ll keep what you said in mind. I used rawget as an example, as I said I’m not trying to prevent anything necessarily dangerous, I just want knowledge over how to do it.
I apologize for being annoying but how would I sandbox things like loadstring
with this?
loadstring
returns a function, so you would pass that on.
local f = loadstring("print(1)")
setfenv(f, { })
f() -- attempt to call a nil value
1 Like