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

@capsule-run/adapter

v0.3.5

Published

Capsule adapter for typescript applications

Readme

Capsule TypeScript Adapter

TypeScript Adapter Release

Execute Python and JavaScript code securely inside Capsule sandboxes from your TypeScript/JavaScript applications.

Installation

npm install @capsule-run/adapter

Usage

Execute Python Code

import { runPython } from '@capsule-run/adapter';

const result = await runPython(`
print("Hello from Python!")
x = 5 + 3
x * 2
`);

console.log(result); // "Hello from Python!\n16"

Execute JavaScript Code

import { runJavaScript } from '@capsule-run/adapter';

const result = await runJavaScript(`
console.log("Hello from JavaScript!");
const x = 5 + 3;
x * 2;
`);

console.log(result); // "Hello from JavaScript!\n16"

Preload Sandboxes (Optional)

The first execution of a sandbox has a cold start (~1 second). You can preload sandboxes to warm them up for faster subsequent executions (~10ms):

import { loadSandboxes, runPython } from '@capsule-run/adapter';

// Preload both sandboxes in parallel
await loadSandboxes();

// Now executions will be faster
const result = await runPython('print("Fast!")');

Or preload individually:

import { loadPythonSandbox, loadJavaScriptSandbox } from '@capsule-run/adapter';

await loadPythonSandbox();      // Warm up Python only
await loadJavaScriptSandbox();  // Warm up JavaScript only

Sessions (Persistent State)

Use Session to run code across multiple calls while preserving state. Each session gets an isolated workspace directory that is automatically cleaned up when the session ends.

import { Session } from '@capsule-run/adapter';

await using s = new Session("python");
await s.run("x = 1");
const result = await s.run("x += 1; x");
console.log(result); // 2

JavaScript sessions work the same way:

await using s = new Session("javascript");
await s.run("x = 1");
const result = await s.run("x += 1; x");
console.log(result); // 2

await using automatically cleans up the session when it goes out of scope. You can also call [Symbol.asyncDispose]() manually if needed.

Import Files

Copy a file or directory from your filesystem into the session workspace. The sandbox code can then access it at the destination path under workspace/.

await using s = new Session("python");

// Import a single file
await s.importFile("./notes.txt", "notes.txt");

// Import a directory
await s.importFile("./data/", "data/");

const result = await s.run(`
with open("workspace/notes.txt") as f:
    content = f.read()
content
`);

Export Files

Export file from the session workspace to your filesystem.

await using s = new Session("python");
await s.importFile("./notes.txt", "notes.txt");

// Export a single file
await s.exportFile("notes.txt", "./exported_notes.txt");

Delete Files

Remove a file from the session workspace:

await using s = new Session("python");
await s.importFile("./notes.txt", "notes.txt");
// ... do some work ...
await s.deleteFile("notes.txt");

Reset State

Clear the session's variable state without touching workspace files:

await using s = new Session("python");
await s.run("x = 42");
s.reset();
const result = await s.run("x"); // throws

How It Works

The adapter compiles Python and JavaScript sandboxes into WebAssembly modules during the build step. When you call runPython() or runJavaScript(), the adapter invokes these pre-built sandboxes using Capsule's runner with the code you provide.

Learn more about Capsule.