Sandboxing Lua Code

User avatar
v-rob
Member
 
Posts: 685
Joined: Thu Mar 24, 2016 03:19
Location: Right behind you.
GitHub: v-rob

Sandboxing Lua Code

by v-rob » Wed Feb 27, 2019 23:31

So, Mesecons has the luacontroller which can run Lua code, but it has protections against things like infinite loops/recursion, memory usage, io/os function calls, and program execution time. How does it protect against these, and how could I do the same thing?

Essentially, I want to have user-inputted Lua code that is sandboxed against malicious code as to not crash servers.
 

wziard
Member
 
Posts: 126
Joined: Mon Oct 29, 2018 19:12

Re: Sandboxing Lua Code

by wziard » Thu Feb 28, 2019 11:19

Use the source, luke!

https://github.com/minetest-mods/meseco ... r/init.lua

I'm not yet really fluent enough in lua to understand everything that's going on there so I can't really tell you how I think it works, because I might be wrong. But if you want to use it you'll have to learn how it works yourself anyway. Slog through that init.lua , looking up everything you don't understand. Then you know how it works. Then you can use it.
 

ShadMOrdre
Member
 
Posts: 534
Joined: Mon Dec 29, 2014 08:07
Location: USA
GitHub: ShadMOrdre
In-game: shadmordre

Re: Sandboxing Lua Code

by ShadMOrdre » Thu Feb 28, 2019 18:08

wziard, this is classic advise.
Use the source, luke!


v-rob,

Other examples to look at are Micus' micupack mod, and the Digilines mods.

micupack, IIRC, has a sandboxed Lua controller. The varous Digilines mods also have interaction with the mesecons controller, and include their own brand of controller.

As wziard said, lots of code reading.....and May the Source be with you!
MY MODS: lib_ecology lib_materials lib_clouds lib_node_shapes ---- Inspired By: Open Source Virtual World Simulator Opensimulator.
 

Exilyth
Member
 
Posts: 71
Joined: Sun Jul 28, 2013 18:46
Location: Earth

Re: Sandboxing Lua Code

by Exilyth » Sat May 11, 2019 12:39

The lua users wiki is not minetest specific, but has an article on sandboxing which may help:
http://lua-users.org/wiki/SandBoxes

But tbh you're probably better off learning from other mods doing sandboxing.
 


Return to Modding Discussion



Who is online

Users browsing this forum: cronvel and 5 guests