0

I need an execution engine for simple user scripts in Python 3 (supposedly some limited subset of it). The thing is supposed to be used in educational game, so the user mainly want just run loops, test conditions and call a few of predefined functions (e.g. move() and turn()).

There are various posts and questions already (e.g. "sandboxing in Python") - they generally conclude that it is hard and existing approaches may have flaws (e.g. pysandbox).

But I think I probably need something different - though I have no idea how to ask google properly. It may be something like limited python interpreter (supposedly also in python) which allows to intercept any function call and variable access and allow only whitelisted ones.

So please advice if there is anything of the kind.

Rodion Gorkovenko
  • 2,670
  • 3
  • 24
  • 37
  • 1
    @deceze thanks, but questions you linked are not duplicates, as I explained explicitly in my question :( – Rodion Gorkovenko Jan 10 '19 at 06:49
  • 1
    Well, "it is hard and existing approaches may have flaws" is pretty much the answer, even if you hope for some magic bullet. The duplicates list various libraries and approaches for limited interpreters. The only thing I could add would be the opposite approach, to build a parser with something like [tag:pyparsing] for custom expressions. It depends on how much of Python you want to reproduce, whether it's simpler to try to reign in real Python, or to build a custom subset of Python from scratch. – deceze Jan 10 '19 at 13:30

0 Answers0