My impression is that you want to create a Lua sandbox in which the Lua scripts are run. By controlling the sandbox environment, you can limit what the scripts can do.
There are a number of similar questions in Stackoverflow.
Then Mozilla has a github that you may find useful. Lua Sandbox Library.
It looks like there was a change from Lua 5.1 to Lua 5.2 which caused a number of the older sandbox techniques to not work so well. Here is a description of approaches for Lua 5.1, Sand Boxes however a function used, setfenv()
is no longer available in Lua 5.2.
There is also Safe Lua which may be helpful.
This article, Sandboxing Lua from C mentions picking libraries to load one at a time to create a specific running environment.
This is how the proposed quasi-sandbox is implemented: normally after
creating new Lua state, host code should call luaL_openlibs() function
to load standard libraries provided by the Lua language, however this
will pull-in many functions which might be unwanted in certain
situations. Therefore, this sandbox pulls-in each library individually
by calling luaL_requiref() and exploits the fact that this function
leaves a table of loaded functions on the top of the Lua stack. The
unwanted functions are then undefined by giving them nil value, ...
However there is also a warning about this approach, unknown dependencies that cause runtime errors.
It is neccessary to give some final notes regarding the proposed
solution: it is not clear whether Lua interpreter will preserve full
functionality in all aspcts outside the unwanted functionality, when
only subset of standard libraries are loaded, however it did worked
well for my solution. In any case some testing is advised. This is due
to the the fact, that some seemingly core functionality of the
language (e.g. ipairs()) is actually provided by the base library.
The best approach is to lock down the scripts so that you can run them as a trusted script even when using sandbox techniques.