I am trying to use How can I create a secure Lua sandbox? to build my own leaky sandbox.
I am trying to create a Lua sandbox where some Lua functions can access some other Lua functions outside the sandbox. For example I want my sandbox to have a special “display” function which can call “print” but not have “print” in the sandbox too.
The main problem is that I am trying to build a sandbox within an already large codebase, so I cannot nil away functions.
How is this possible?
The solution has to be a pure Lua function due to no fault of mine.
When you create a sandbox, you do it by cherry picking functions and values from a larger environment to create a new sandbox environment. You do not need to destroy or “nil out” anything in the original environment.
So,
prints
whereas
fails with