A binding to Node.js + vm2, helps you execute JavaScript safely.
Project description
A Python 3 to Node.js + vm2 binding, helps you execute JavaScript safely.
vm2
vm2 is a node module to create real sandbox in node. The official node API vm just create isolate scope and doesn’t prevent harmful code to damage your computer.
How it works
This module will launch a Node.js REPL server, which use JSON to communicate. All JavaScript code are encoded in JSON and sent to the server, after server executed the code in vm2, it reponse the result and let the module decode it back to Python values.
Install
You need Node.js.
Install node_vm2 from pypi wheel.
pip install node_vm2
Also make sure you have node executable in PATH, or you can specify the executable with environment variable NODE_EXECUTABLE.
Additionally, you will need npm to build node_vm2 from source.
Usage
Most of the APIs are compatible with vm2.
from node_vm2 import VM
with VM() as vm:
result = vm.run("""
var sum = 0, i;
for (i = 0; i < 10; i++) sum += i;
sum;
""")
print(result)
API reference
Changelog
0.1.0 (Mar 23, 2017)
First release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file node_vm2-0.1.0.tar.gz
.
File metadata
- Download URL: node_vm2-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cca6032ebcfa94857c650a60ef91bda62ab81d599bafcd8435238bb87ad4f28 |
|
MD5 | 1c5a02628fdf8f3db4b42b76ba31dfa6 |
|
BLAKE2b-256 | b4632f68889225771aceb6dd96b1b8d205ee8f5ebad1bce4e834fddf26f34062 |
File details
Details for the file node_vm2-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: node_vm2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c8b1e25f425062ccc82f185941f1aef882c9a2d5d3fe8e53f64e1d02b222ecf |
|
MD5 | 172e3adca179a90cda61f2811dd406a2 |
|
BLAKE2b-256 | 2006f786f63573e4d8cae3d6874aba29c6dd900926d7e840101ecc8f8f2ac1ee |