
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@apeleghq/lot
Advanced tools
Welcome to @apeleghq/lot — the versatile ECMAScript sandbox
you've been looking for!
Our sandbox supports multiple runtimes and allows for bidirectional communication, ensuring you have the flexibility and security to run your code in various environments.
MessageEvent class and event listeners for secure
communication using the structured clone algorithmFunction and eval, to prevent
direct code executionTo install, run:
npm install "@apeleghq/lot"
yarn add "@apeleghq/lot"
Using our sandbox is easy! First, import the desired sandbox function, then call
it with your code and any additional parameters. Here's an example using
browserSandbox:
import { browserSandbox } from '@apeleghq/lot';
const sandbox = await browserSandbox(`
/* sandboxed code*/;
module.exports={hello:(name)=>\`Hello, ${name}!\`};
`);
const result = await sandbox('hello', 'World');
console.log(result); // Output: "Hello, World!"
Our sandbox provides two interfaces:
export interface IPerformTask {
(op: string, ...args: unknown[]): Promise<unknown>;
}
export interface ISandbox {
(
script: string,
allowedGlobals?: string[] | undefined | null,
externalMethods?: Record<string, unknown> | null,
abort?: AbortSignal,
options?: TSandboxOptions,
): Promise<IPerformTask>;
}
export type TSandboxOptions = {
browserRequireWorker?: boolean;
workerType?: WorkerOptions['type'];
}
ISandbox is an interface for the browserSandbox, nodejsSandbox and
workerSandbox functions. It takes a string script representing the code to
be sandboxed, an optional array of allowed global variables allowedGlobals, an
optional object of external methods externalMethods, and an optional
AbortSignal abort. It returns a promise that resolves to an implementation of
IPerformTask.
IPerformTask is an interface for the result of the various sandbox function.
It takes a string op representing the function name and a list of arguments,
and it returns a promise that resolves to the result of the task.
The script to be sandboxed, script, must expose an object in module.exports
with a dictionary of the different functions that can be called from outside.
The type of module.exports is Record<string, typeof Function.prototype>.
We welcome any contributions and feedback! Please feel free to submit pull requests, bug reports or feature requests to our GitHub repository.
⚠️ Please note that even though we have implemented several security measures,
it's important to understand that sandbox escapes are always a possibility.
Running untrusted code in Node.js is especially risky due to its inherent
platform limitations. Our sandbox relies on node:vm, which was not designed
for running untrusted code.
To mitigate these risks, we strongly recommend taking a security-in-depth
approach and relying on additional security mechanisms such as process
isolation, seccomp(2), pledge(2), ProcessSystemCallDisablePolicy and
SELinux, to name a few. Where feasible, we also recommend static code analysis
and code reviews, as well as adequate auditing and logging.
Note that the sandbox does not prevent denial-of-service attacks such as infinite loops or memory exhaustion. It's important to take appropriate measures to prevent these types of attacks, such as setting resource limits or using timeouts.
This project is released under the ISC license. Check out the LICENSE file for
more information.
FAQs
Sandbox for isolating ECMAScript code
We found that @apeleghq/lot demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.