# easy-vm

> Run securely untrusted code with whitelisted Node modules

Latest version **1.3.0** (published 2019-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install easy-vm
pnpm add easy-vm
yarn add easy-vm
bun add easy-vm
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2019-09-07 |
| First published | 2018-04-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | sentialx |
| Maintainers | sential |
| Keywords | vm, nodejs |

## Links

- npm: https://www.npmjs.com/package/easy-vm
- Repository: https://github.com/sentialx/easy-vm
- Homepage: https://github.com/sentialx/easy-vm#readme
- Issues: https://github.com/sentialx/easy-vm/issues
- npm.io page: https://npm.io/package/easy-vm

## Dependencies (2)

- [ts-loader](https://npm.io/package/ts-loader.md) 6.0.4
- [typescript](https://npm.io/package/typescript.md) 3.6.2

## Recent versions

- 1.3.0 (latest) — 2019-09-07
- 1.2.3 — 2019-09-06
- 1.2.2 — 2019-07-28
- 1.2.1 — 2018-07-25
- 1.2.0 — 2018-07-25
- 1.1.0 — 2018-04-08
- 1.0.2 — 2018-04-07
- 1.0.1 — 2018-04-07
- 1.0.0 — 2018-04-06

## README

# easy-vm

`easy-vm` is a simple Node.js library which helps with running securely untrusted code with whitelisted Node modules.

# Installation

```bash
$ npm install easy-vm
```

# Quick example
```javascript
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.

---
_Source: https://npm.io/package/easy-vm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
