What i do know
So i know what a sandbox is. I know what it's used for, and how it can be useful in the right situation. I also know about a lot about function environments, tables, and metatables. Just a small overview on stuff i know to spare any explanation on.
The question
How can i make my sandbox attempt more secure? More specifically, how can i prevent it from being bypassed with the following code:
setfenv(1,setmetatable({},{
__index = function(t,k)
if k == "workspace" then
return nil
else
return getfenv()[k]
end
end
}))
print(workspace) -- > nil
setfenv(1,getfenv(print)) -- bypassed, because i can set a new environment with the original one from print.
print(workspace) -- > nil
The problem
So, i know what the problem is, but have no idea how to fix it. I could say any of the following to bypass this little sandbox:
setfenv(1,getfenv(print))
setfenv(1,getfenv(unpack))
setfenv(1,getfenv(script))
-- Or any other built-in global that the __index metamethod returns.
So, if anyone happens to have some insight on sandboxing, or even environments and metatables, i'd really appreciate some help. Thanks for reading.

2 comments
Define sandbox because I never heard that in any programming language ever .-.
A sandbox is a virtual space (a program) where code can be ran under certain instruction (i.e, disabling access to potentially harmful information). For example, one person may remove another person from a game with unsandboxed code, but with sandboxed code that would prevent that from happening.