[...] local source = "rawset(_ENV, 'foo', function() print('bar') end); foo()" local chunk = load(source, "@a_chunk", "t", proxy) chunk() -- prints 'bar' env.foo() -- prints 'foo' if proxy ~= env, 'bar' if proxy == env