Page MenuHome

Proof of concept restricted Python evaluation (using numba)
AbandonedPublic

Authored by Campbell Barton (campbellbarton) on Mar 18 2016, 6:51 AM.

Details

Summary

This patch uses numba to execute Python byte-code without access to CPython API (no open(), import, or modules like os.*, shutil.*... etc).

Checked on the numba mailing list and apparently numba is not fully secure, but they seem open to having a restricted mode in numba, which shouldn't be so hard to support. [0]

Tested on glass-half file (01_render.blend), and it works with around same performance as with full Python.
However initial jit complication is very slow, (over ~1 min!).

Pros

  • Works with math API and numeric Python expressions.
  • Off the shelf solution we don't have to maintain.
  • No large extra dependencies.

Cons

  • Slow initial expression compilation.
  • Complicates build process (we would probably include pre-compiled for OSX/Windows, for Linux it needs to link with LLVM and depends on numpy).
  • Not *entirely* secure (yet), apparently, though it can be supported.

Submitting this diff for reference, since it works and may help in finding a good solution.

[0]: https://groups.google.com/a/continuum.io/forum/?utm_medium=email&utm_source=footer#!msg/numba-users/0zVhy_B9XCA/bYepSv59GwAJ

Diff Detail

Repository
rB Blender
Branch
TEMP-PYSANDBOX

Event Timeline

Campbell Barton (campbellbarton) retitled this revision from to Proof of concept restricted python evaluation.
Campbell Barton (campbellbarton) retitled this revision from Proof of concept restricted python evaluation to Proof of concept restricted Python evaluation.Mar 18 2016, 7:05 AM
Campbell Barton (campbellbarton) retitled this revision from Proof of concept restricted Python evaluation to Proof of concept restricted Python evaluation (using numba).Mar 19 2016, 12:11 PM

Second patch on same topic. Which way to go? Both? :)

@Sergey Sharybin (sergey): I'm leaning towards the second one (bytecode stuff). This one has the dual downsides of extra libs/dependencies (with no-so-nice build processes) along with a performance cost (initial startup/setup) of the numba environment.

Closing as I don't think this worked all that well in practice, the time to JIT compile functions is prohibitively slow.