Skip to main content

Restricted Python Virtual Machine

Project description

Restricted Python Virtual Machine

Restricted Python Virtual Machine (R-PVM) implemented by pure python.


  • aim for complete safe sandbox
  • designed for Python3.6 bytecode
  • execute one by one
  • good for smart contract of crypto currency
  • No warranty and unstable


  • cannot use MAKE_FUNCTION op (lambda, comprehension and inner fnc)
  • cannot use async/await
  • limit to execute function
  • YOU must select safe function


pip3 install rpvm

How to use

from rpvm.vm import VirtualMachine
from RestrictedPython import safe_builtins, safe_globals
source = """
a = 1
b = 2
c = a + b
code = compile(source, '<example>', 'exec')
b = safe_builtins.copy()
l = dict()
g = safe_globals.copy()
vm = VirtualMachine(code, b, l, g)
steps = 0
max_steps = 500
while not vm.finish and steps < max_steps:
    steps += 1
print("complete?", vm.finish)
print("result", vm.return_value)
print("c is", l['c'])


python3 -m pytest tests



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpvm-0.1.0a1.tar.gz (8.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page