lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,
If you want to protect your _G, don't share it with your sandbox.
If you want to have some standard libs in your isolated env, just link
them exclusively.

local env = {
    require = require,
}
load([[ require "ext" ]], "foo.lua", "t", env)

But actually for the complete protection you'd need to go to a C
level, create a separate lua state, load standard libs there and exec
your code there:

L = lua_newstate(...);
luaL_openlibs(L);
luaL_loadbufferx(L, "require 'ext'", 13, "foo.lua", NULL);
lua_call(L, 0, 0);
lua_close(L);