Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

easy-vm

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-vm

Run securely untrusted code with whitelisted Node modules

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

easy-vm

easy-vm is a simple Node.js library which helps with running securely untrusted code with whitelisted Node modules.

Installation

$ npm install easy-vm

Quick example

const EasyVM = require('easy-vm');

const vm = new EasyVM({
  console: true,
  sandbox: {
    test: 'A test variable'
  },
  require: {
    builtin: ['fs'],
    mock: {
      fs: {
        readFile: (path: string) => {
          console.log("Nice try!");
        }
      }
    }
  }
});

vm.run(`
  const fs = require('fs');
  fs.readFile(''); // Outputs: Nice try!
  
  console.log(test); // Outputs: A test variable
`);

Documentation

Class EasyVM

An EasyVM can be used to create a sandbox.

new EasyVM(options)

  • options VMOptions
    • console boolean - Whether to enable console in the sandbox or not.
    • sandbox object - A global object in VM
    • require VMRequireOptions | false - False to disable require or object to enable require with options.
      • builtin string[] - Array of allowed builtin modules, Use ['*'] to accept all.
      • mock object - Collection of mocked Node modules.
Methods

EasyVM.run(code, filename)

  • code string
  • filename string (optional) - Path to which Node's require() relates.

Keywords

FAQs

Package last updated on 07 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc