Python interpreter on Android can be an implementation. An example is
Skulpt. You are not running a python interpreter on their server. It mimics python. Thus you can restrict what modules you import, read and write permissions, etc.
Termux appears to be similar based on researching. Although i have never used it so i cant say 100% either way.
Quote:Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required.
Quote:is achieved using VOC, a tool that compiles Python source code to Java class files. This allows Python code to be executed as a native binary on the JVM.
more
info.