Metadata-Version: 2.0
Name: node-vm2
Version: 0.1.0
Summary: A binding to Node.js + vm2, helps you execute JavaScript safely.
Home-page: https://github.com/eight04/node_vm2
Author: eight
Author-email: eight04@gmail.com
License: MIT
Keywords: node,js,sandbox,execute,javascript
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Win32 (MS Windows)
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: Chinese (Traditional)
Classifier: Operating System :: Microsoft :: Windows :: Windows 7
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: JavaScript
Classifier: Topic :: Software Development :: Libraries

node_vm2
========

.. image:: https://api.codacy.com/project/badge/Grade/fb30c7193b6b43cf818457e3ff23e60c
   :target: https://www.codacy.com/app/eight04/node_vm2?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=eight04/node_vm2&amp;utm_campaign=Badge_Grade

.. image:: https://readthedocs.org/projects/node-vm2/badge/?version=latest
   :target: http://node-vm2.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status

A Python 3 to Node.js + vm2 binding, helps you execute JavaScript safely.

vm2
---

`vm2 <https://github.com/patriksimek/vm2>`__ is a node module to create **real** sandbox in node. The official node API `vm <https://nodejs.org/api/vm.html>`__ 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.

https://nodejs.org/

Install node_vm2 from pypi wheel.

.. code-block::

   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 <https://github.com/patriksimek/vm2>`__.

.. code-block:: python

   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
-------------

http://node-vm2.readthedocs.io/

Changelog
---------

-  0.1.0 (Mar 23, 2017)

   -  First release


