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

mastra-opensandbox

v0.1.0

Published

OpenSandbox support for the Mastra AI agent framework

Readme

mastra-opensandbox

OpenSandbox integration for the Mastra agent framework.

Provides a WorkspaceSandbox implementation, background process management, Code Interpreter tools, and network policy controls for running AI agent workloads in isolated Docker containers.

Features

  • OpenSandboxSandbox — Full WorkspaceSandbox implementation with lifecycle management (start, stop, destroy, reconnect)
  • OpenSandboxProcessManager — Background process spawning and management via sandbox sessions
  • Code Interpreter ToolsrunCode, writeFile, readFile Mastra tools for multi-language code execution (Python, JavaScript, TypeScript, Java, Go, Bash)
  • Network Policy — Egress controls at sandbox creation time and runtime patching

Prerequisites

  • Node.js >= 22.13.0
  • Docker (for running OpenSandbox server)
  • OpenSandbox server running (self-hosted or cloud)

Installation

npm install mastra-opensandbox @mastra/core zod

Quick Start

1. Start the OpenSandbox server

# Using docker-compose (included in this repo)
docker-compose up -d

# Pre-pull the code interpreter image
docker pull opensandbox/code-interpreter:latest

2. Create an agent with a sandbox workspace

import { Agent } from '@mastra/core/agent';
import { Workspace } from '@mastra/core/workspace';
import { OpenSandboxSandbox, createCodeInterpreterTools } from 'mastra-opensandbox';

const sandbox = new OpenSandboxSandbox({
  domain: 'localhost:8080',
  image: 'opensandbox/code-interpreter:latest',
  timeoutSeconds: 600,
});

const tools = createCodeInterpreterTools(sandbox);

const agent = new Agent({
  name: 'dev-agent',
  model: { provider: 'ANTHROPIC', name: 'claude-sonnet-4-6' },
  instructions: 'You are a coding assistant. Use the sandbox to run code.',
  workspace: new Workspace({ sandbox }),
  tools,
});

const response = await agent.generate('Run Python: print(2 + 2)');

API Reference

OpenSandboxSandbox

Main sandbox class implementing Mastra's WorkspaceSandbox interface.

const sandbox = new OpenSandboxSandbox(config?: OpenSandboxConfig);

OpenSandboxConfig

| Option | Type | Default | Description | |--------|------|---------|-------------| | domain | string | process.env.OPENSANDBOX_DOMAIN ?? 'localhost:8080' | Server host:port | | apiKey | string | process.env.OPENSANDBOX_API_KEY | API key | | protocol | 'http' \| 'https' | 'http' | Connection protocol | | requestTimeoutSeconds | number | 30 | HTTP timeout | | image | string | 'opensandbox/code-interpreter:latest' | Docker image | | entrypoint | string[] | — | Custom entrypoint | | env | Record<string, string> | — | Environment variables | | timeoutSeconds | number \| null | 600 | Sandbox TTL (null = no expiry) | | metadata | Record<string, string> | — | Metadata labels | | networkPolicy | NetworkPolicy | — | Egress policy | | sandboxId | string | — | Reconnect to existing sandbox | | workingDirectory | string | '/home/user' | Default working directory |

Methods

| Method | Description | |--------|-------------| | start() | Create or connect to sandbox | | stop() | Pause the sandbox | | destroy() | Kill and clean up | | executeCommand(cmd, args?, opts?) | Run a shell command | | getInfo() | Get sandbox status | | getInstructions() | System prompt instructions | | getEgressPolicy() | Get current network policy | | patchEgressRules(rules) | Update egress rules at runtime |

Properties

| Property | Type | Description | |----------|------|-------------| | instance | Sandbox | Raw OpenSandbox SDK handle (throws if not started) | | connectionConfig | ConnectionConfig | Current connection config | | processes | OpenSandboxProcessManager | Background process manager |

createCodeInterpreterTools(sandbox)

Creates three Mastra tools for code execution:

  • runCode — Execute code in Python, JS, TS, Java, Go, or Bash with session state
  • writeFile — Write a file inside the sandbox
  • readFile — Read a file from the sandbox
const tools = createCodeInterpreterTools(sandbox);
// tools.runCode, tools.writeFile, tools.readFile

OpenSandboxProcessManager

Background process management (accessible via sandbox.processes):

const handle = await sandbox.processes.spawn('node server.js');
const list = await sandbox.processes.list();
await sandbox.processes.kill(handle.pid);

Network Policy

Control outbound network access:

// At creation time
const sandbox = new OpenSandboxSandbox({
  networkPolicy: {
    defaultAction: 'deny',
    egress: [
      { action: 'allow', target: 'pypi.org' },
      { action: 'allow', target: 'npmjs.org' },
    ],
  },
});

// At runtime
await sandbox.patchEgressRules([
  { action: 'allow', target: 'github.com' },
]);

Deployment Modes

| Mode | Configuration | |------|---------------| | Local Docker | domain: 'localhost:8080' | | Self-hosted (same network) | domain: 'opensandbox.internal:8080' | | Self-hosted (TLS) | domain: 'sandbox.mycompany.com', protocol: 'https', apiKey: '...' | | Kubernetes | domain: 'opensandbox-server.sandbox-ns.svc:8080' |

Development

# Install dependencies
npm install

# Build
npm run build

# Type check
npm run typecheck

# Run unit tests
npm run test

# Run integration tests (requires Docker + OpenSandbox server)
docker-compose up -d
npm run test:integration

# Lint
npm run lint

# Format
npm run format

License

The project is published under the BSD 3-Clause license. For details see the LICENSE file.