For a project I'm working on, I need to run untrusted code. I was originally thinking of using pysandbox, but the creator said it wasn't safe, then I tried PyPy but couldn't get it to work on my Windows PC, and now I'm considering running a sandboxed Lua script through Python. Is that even possible with any sort of Python module? I couldn't find anything specific enough to answer this question. Thank y'all and have a great day!
Asked
Active
Viewed 397 times
0
-
If you have Lua installed on your machine, you can use `subprocess` to run it as described [in this answer](https://stackoverflow.com/a/30841968/1175455). – Harry Cutts Oct 15 '18 at 22:48
-
Possible duplicate of [Run Lua script from Python](https://stackoverflow.com/questions/30841738/run-lua-script-from-python) – Harry Cutts Oct 15 '18 at 22:49
-
But how can I run it in a _sandbox?_ @HarryCutts – Masterfoxify Oct 15 '18 at 23:54
-
Ah, I see. Lua has some built-in sandboxing support, so you could write your own Lua script which wraps the untrusted Lua code. See [How can I create a secure Lua sandbox?](https://stackoverflow.com/questions/1224708/how-can-i-create-a-secure-lua-sandbox). – Harry Cutts Oct 16 '18 at 00:48
-
So essentially run a Python script that runs a Lua script that runs a sandbox of an untrusted Lua script? @HarryCutts – Masterfoxify Oct 16 '18 at 01:11
-
Pretty much. It's a bit complicated, I know. I've never tried it, but you might want to look at the `lupa` Python module, which seems to have [a similar sandboxing feature](https://pypi.org/project/lupa/#restricting-lua-access-to-python-objects). – Harry Cutts Oct 16 '18 at 20:18