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

@directive-run/sandbox

v0.3.9

Published

Execute Directive snippets server-side and return a structured transcript (logs + facts + errors). Consumed by @directive-run/mcp's run_in_sandbox tool and directive.run/playground's live DevTools panel. Uses worker_threads + esbuild bundling + an AST all

Readme

@directive-run/sandbox

Execute Directive snippets server-side and return a structured transcript (logs, facts, errors). Used by @directive-run/mcp's run_in_sandbox tool and by directive.run/playground's live DevTools panel.

What it does

Takes a TypeScript snippet (single source string OR a paired library + runner files: [{path, source}] array — same shape playground_link accepts), validates it against an AST allowlist, bundles the multi-file payload via esbuild, and executes the result in a bounded worker_threads sandbox. Returns:

interface SandboxResult {
  logs: string[];                       // captured console.log/warn/error lines
  facts: Record<string, unknown>;       // system.facts.$store.toObject() snapshot
  errors: string[];                     // structured error messages
  durationMs: number;
  timedOut: boolean;
}

The bundler injects an early-capture immediately after createSystem(...), so the post-mortem snapshot survives mid-runner errors — a validation throw inside await system.settle() still hands you the init-state facts.

Sandbox boundary

Three layers:

  1. AST allowlist validator (ts-morph). Imports are restricted to a curated @directive-run/* set + relative ./*.js:
    • Allowed: core, ai, query, react, vue, svelte, solid, lit, el, optimistic, timeline, mutator, knowledge, scaffold, claude-plugin, lint (16 packages — anything an end-user demo realistically composes from).
    • Denied: cli, mcp, sandbox, vite-plugin-api-proxy (build / CLI / sandbox-meta tooling — no legitimate use inside a sandboxed demo).
    • Everything else (node:fs, express, @sizls/*, etc.) is rejected.
    • Identifier references to FS / network / eval surfaces (process, require, fetch, fs, child_process, eval, new Function, setTimeout, Buffer, etc.) are rejected as free identifiers.
    • Property-access bypass chains are rejected (v0.3.0): globalThis.process, globalThis.fetch, globalThis["X"] bracket access with string literal, .constructor access on any value, Function(...) call without new, Reflect.get/has/getOwnPropertyDescriptor(globalThis, "X") smuggle chains. The AE security audit in docs/AE-AUDIT-SANDBOX.md traces these PoCs and how v0.3.0 closes them.
  2. esbuild bundler. Virtualizes the multi-file payload into a single ESM string with @directive-run/* externalized. Throws on imports that can't be resolved against the in-memory file map.
  3. worker_threads.Worker with resourceLimits (32 MB heap, 16 MB code) and a clamped wall-clock budget ([100ms, 10s], default 5s). The worker is hard-terminated on timeout — no cooperative cancellation needed.

Resource limits are heap-only — workers share the parent process's FS / network access. The allowlist validator is what actually prevents sandbox escape; the worker layer adds OOM / runaway-CPU bounding on top.

API

import { runInSandbox } from "@directive-run/sandbox";

const result = await runInSandbox({
  files: [
    { path: "src/counter.ts", source: moduleSource },
    { path: "src/main.ts", source: runnerSource },
  ],
  timeoutMs: 5000,
});

console.log(result.logs);   // ["[start] count= 0", "[settled] count= 2"]
console.log(result.facts);  // { count: 2 }

The single-source shortcut runInSandbox({ source: "..." }) maps onto src/main.ts internally — convenient for already-runnable snippets from get_example / fix_code.

See also

  • @directive-run/mcp — wraps runInSandbox as the run_in_sandbox MCP tool, returns the transcript to the AI client alongside a playgroundUrl.
  • @directive-run/scaffoldgenerateRunner produces the canonical runner shape this sandbox expects to execute (createSystemstart() → dispatch → settle() → log).