Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
/ vm Public archive

This repository provides a secured sandbox to execute unsafe JavaScript code

License

Notifications You must be signed in to change notification settings

hapify/vm

Repository files navigation

Hapify VM

Description

This repository provides a secured sandbox to execute unsafe JavaScript code

Build Status codecov

Usage

Basic usage

import { HapifyVM } from '@hapify/vm';

const script = `const concat = a + b; return concat;`;
const result = new HapifyVM().run(script, { a: 'hello', b: 'world' }); // result = 'hello world'

Advanced usage

import { HapifyVM } from '@hapify/vm';

const script = `const sum = a + b; return sum;`;
const options = {
    timeout: 200, // Maximum script execution time. Default to 1000ms.
    allowAnyOutput: true, // Allow the input script to return any data type. Default to false.
    eval: true // Allow function constructors (Function, GeneratorFunction, etc)
};
const result = new HapifyVM(options).run(script, { a: 1, b: 2 }); // result = 3

About

This repository provides a secured sandbox to execute unsafe JavaScript code

Resources

License

Stars

Watchers

Forks

Packages

No packages published