npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

secure-exec

v0.2.22

Published

Secure Node.js execution for AI agents: run untrusted JavaScript and TypeScript in an isolated VM.

Readme

Install

npm install secure-exec

Requires Node.js 22+ on Linux or macOS.

Run Code

Each call runs in a fresh VM that is disposed when the call finishes. Nothing is shared between calls.

import { evaluate, execute } from "secure-exec";

const sum = await evaluate<number>("1 + 2");
if (sum.outcome === "succeeded") console.log(sum.value); // 3

const run = await execute(`console.log("hello")`, {
  output: { capture: "all" },
  timeoutMs: 5_000,
});
console.log(run.stdout); // hello

evaluate takes one expression and returns its JSON value; wrap several statements in a function. execute runs a whole module for its side effects.

outcome is succeeded, failed, cancelled, or timed_out. Every outcome other than succeeded carries an error, and guest stack traces arrive on stderr when you capture it.

Configure the VM

VM options go on the call: permissions, limits, mounts, and the rest of the agentOS VM options. External network access is denied unless you allow it, and a policy is merged over the defaults.

await evaluate(
  `(async () => {
    const response = await fetch("https://example.com");
    await response.text();
    return response.status;
  })()`,
  { permissions: { network: "allow" } },
);

Keep things with a VM

The functions above are one-shot conveniences. When files, installed packages, or a running server should outlast one call, create a VM. It is an agentOS VM with Secure Exec's defaults.

import { createVm } from "secure-exec";

const vm = await createVm({ permissions: { network: "allow" } });
try {
  await vm.npm.install(["zod"]);
  await vm.filesystem.writeFile("/workspace/data.json", JSON.stringify({ n: 40 }));

  const result = await vm.javascript.evaluate<number>(
    `import("node:fs").then((fs) => JSON.parse(fs.readFileSync("/workspace/data.json", "utf8")).n + 2)`,
  );

  const server = await vm.javascript.spawn(`/* long-running code */`);
  await vm.process.kill(server.pid);
} finally {
  await vm.dispose();
}

vm.javascript, vm.typescript, vm.npm, vm.filesystem, vm.network, and vm.process behave exactly as they do in agentOS.

Keep variables with a context

Each call on a VM starts with fresh JavaScript memory. A context keeps it, like a REPL, and several contexts run in parallel in one VM.

const context = await vm.createContext();

await context.execute("globalThis.total = 40");
const result = await context.evaluate<number>("total + 2");

await context.reset();   // clear state
await context.dispose(); // delete the context, keep the VM

Host functions

Give the code your own functions without giving it your credentials. Each collection is a global inside the VM, and each function is async.

import { evaluate, hostFunction, hostFunctions } from "secure-exec";
import { z } from "zod";

const orders = hostFunctions({
  name: "orders",
  description: "Look up customer orders.",
  functions: {
    list: hostFunction({
      description: "List a customer's orders.",
      inputSchema: z.object({ customer: z.string() }),
      execute: ({ customer }) => db.orders.findMany({ customer }),
    }),
  },
});

await evaluate(`orders.list({ customer: "c_123" }).then((rows) => rows.length)`, {
  hostFunctions: [orders],
});

TypeScript

secure-exec/typescript has the same execute and evaluate, plus check. Running TypeScript strips types without checking them, so check first when it matters.

import { check, evaluate } from "secure-exec/typescript";

const checked = await check(`const total: number = "nope";`);
for (const diagnostic of checked.diagnostics) console.log(diagnostic.message);

Lifecycle

The first call starts a shared sidecar process. Call init() at startup to pay that cost ahead of time, and shutdown() to stop it, for example in a test teardown hook.

import { init, shutdown } from "secure-exec";

await init();
// ...
await shutdown();

More

Need Python? Use the agentOS Python execution API, which has the same execute and evaluate shape.

For processes, filesystem access, and agent sessions, use @rivet-dev/agentos-core directly. Read the documentation, or browse the examples in secure-exec/examples.