New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@locker/sandbox

Package Overview
Dependencies
Maintainers
8
Versions
257
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@locker/sandbox

Lightning Web Security sandboxing library

  • 0.23.13
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-17.59%
Maintainers
8
Weekly downloads
 
Created
Source

@locker/sandbox

Lightning Web Security sandboxing library

Installation

$ yarn add @locker/sandbox

Usage

The evaluateInSandbox() function:

import { evaluateInSandbox } from '@locker/sandbox';

let sandboxed;
// Evaluate source text in a sandbox using
// `evaluateInSandbox(key, sourceText, context, endowments)`. The function has
// no return value.
evaluateInSandbox(
    // The key of the sandbox to evaluate source text in. One sandbox is created
    // per key regardless of the number of calls to `evaluateInSandbox()`.
    'sandbox',
    // The source text to evaluate in the sandbox.
    `$lockerEvalContext$(${
        // Function body to coerce to a string. Using a function and coercing
        // it to a string has the benefit of working with minifiers.
        function () {
            // Call to a provided endowment value.
            logger('inside sandbox');
            // Other code to sandbox...
        }
    })`,
    // The value of the optional sandbox context binding `$lockerEvalContext$`
    // that may be used to initialize sandboxed code. The binding can be an object,
    // function, or anything else. The `$lockerEvalContext$` binding can only be
    // accessed a once per sandbox evaluation and is set to `undefined` after
    // the synchronous sandbox evaluation.
    (def) => {
        sandboxed = def;
    },
    // The optional endowments object whose property descriptors are used to
    // define properties on the sandboxed global object. Behind the scenes the
    // `$lockerEvalContext$` is defined using the same endowments feature.
    { logger: console.log.bind(console) }
);

FAQs

Package last updated on 29 Jan 2025

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