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

isolated-vm

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isolated-vm

Access to multiple isolates

  • 3.3.10
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is isolated-vm?

The isolated-vm npm package allows you to create isolated JavaScript environments, or 'isolates', which can run code independently of each other. This is useful for running untrusted code, sandboxing, and creating secure execution contexts.

What are isolated-vm's main functionalities?

Creating an Isolate

This feature allows you to create a new isolated environment with a specified memory limit. The code sample demonstrates creating an isolate with a 128MB memory limit.

const ivm = require('isolated-vm');
const isolate = new ivm.Isolate({ memoryLimit: 128 });
console.log('Isolate created with 128MB memory limit');

Running Scripts in an Isolate

This feature allows you to compile and run scripts within an isolate. The code sample demonstrates creating a context, compiling a script, and running it within the isolate.

const ivm = require('isolated-vm');
const isolate = new ivm.Isolate({ memoryLimit: 128 });
(async () => {
  const context = await isolate.createContext();
  const script = await isolate.compileScript('let a = 1 + 2; a');
  const result = await script.run(context);
  console.log('Script result:', result); // Output: Script result: 3
})();

Transferring Data Between Isolates

This feature allows you to transfer data between the main environment and the isolate. The code sample demonstrates setting a global variable in the isolate and retrieving its value.

const ivm = require('isolated-vm');
const isolate = new ivm.Isolate({ memoryLimit: 128 });
(async () => {
  const context = await isolate.createContext();
  const jail = context.global;
  await jail.set('global', jail.derefInto());
  const script = await isolate.compileScript('global.a = 1 + 2');
  await script.run(context);
  const a = await jail.get('a');
  console.log('Value of a:', a); // Output: Value of a: 3
})();

Other packages similar to isolated-vm

FAQs

Package last updated on 24 Jan 2021

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