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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@computesdk/codesandbox

v1.5.3

Published

CodeSandbox provider for ComputeSDK

Readme

@computesdk/codesandbox

CodeSandbox provider for ComputeSDK - Execute code in secure, isolated CodeSandbox environments with full filesystem and development environment support.

Installation

npm install @computesdk/codesandbox

Setup

  1. Get your CodeSandbox API key from codesandbox.io/t/api
  2. Set the environment variable:
export CSB_API_KEY=your_api_key_here

Usage

With ComputeSDK

import { createCompute } from 'computesdk';
import { codesandbox } from '@computesdk/codesandbox';

// Set as default provider
const compute = createCompute({ 
  provider: codesandbox({ apiKey: process.env.CSB_API_KEY }) 
});

// Create sandbox
const sandbox = await compute.sandbox.create();

// Execute JavaScript/Node.js code
const result = await sandbox.runCode(`
const message = "Hello from CodeSandbox!";
console.log(message);

const data = { users: 3, tasks: 15 };
console.log(JSON.stringify(data, null, 2));
`);

console.log(result.stdout);
// Output:
// Hello from CodeSandbox!
// {
//   "users": 3,
//   "tasks": 15
// }

// Execute Python code
const pythonResult = await sandbox.runCode(`
import json
data = {"framework": "CodeSandbox", "language": "Python"}
print(json.dumps(data, indent=2))
print(f"Running in: {data['framework']}")
`, 'python');

console.log(pythonResult.stdout);
// Output:
// {
//   "framework": "CodeSandbox",
//   "language": "Python"
// }
// Running in: CodeSandbox

// Clean up
await compute.sandbox.destroy(sandbox.sandboxId);

Direct Usage

import { codesandbox } from '@computesdk/codesandbox';

// Create provider
const provider = codesandbox({ 
  apiKey: 'your_api_key',
  templateId: 'universal', // Optional: specify template
  timeout: 600000 // 10 minutes
});

// Use with compute singleton
const sandbox = await compute.sandbox.create({ provider });

Configuration

Environment Variables

export CSB_API_KEY=your_api_key_here

Configuration Options

interface CodesandboxConfig {
  /** CodeSandbox API key - if not provided, will use CSB_API_KEY env var */
  apiKey?: string;
  /** Template to use for new sandboxes (defaults to universal template) */
  templateId?: string;
  /** Default runtime environment */
  runtime?: 'python' | 'node';
  /** Execution timeout in milliseconds */
  timeout?: number;
}

Features

  • Code Execution - Python and Node.js runtime support
  • Command Execution - Run shell commands in sandbox
  • Filesystem Operations - Full file system access via CodeSandbox API
  • Template Support - Create sandboxes from custom templates
  • Auto Runtime Detection - Automatically detects Python vs Node.js
  • Development Environment - Full development setup with package managers
  • Persistence - Files persist across hibernation/resume cycles
  • Snapshot/Resume - Fast sandbox restoration from snapshots

API Reference

Code Execution

// Execute Node.js code
const result = await sandbox.runCode(`
const fs = require('fs');
const data = { timestamp: Date.now() };
console.log('Processing data:', JSON.stringify(data));
`);

// Execute Python code  
const result = await sandbox.runCode(`
import datetime
import json

data = {'timestamp': datetime.datetime.now().isoformat()}
print('Processing data:', json.dumps(data))
`, 'python');

// Auto-detection (based on code patterns)
const result = await sandbox.runCode('print("Auto-detected as Python")');

Command Execution

// List files
const result = await sandbox.runCommand('ls', ['-la']);

// Install Node.js packages
const result = await sandbox.runCommand('npm', ['install', 'lodash']);

// Install Python packages
const result = await sandbox.runCommand('pip', ['install', 'requests']);

// Run development server
const result = await sandbox.runCommand('npm', ['run', 'dev']);

Filesystem Operations

// Write file
await sandbox.filesystem.writeFile('/project/workspace/app.js', `
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.json({ message: 'Hello from CodeSandbox!' });
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
`);

// Read file
const content = await sandbox.filesystem.readFile('/project/workspace/package.json');

// Create directory
await sandbox.filesystem.mkdir('/project/workspace/src');

// List directory contents
const files = await sandbox.filesystem.readdir('/project/workspace');

// Check if file exists
const exists = await sandbox.filesystem.exists('/project/workspace/app.js');

// Remove file or directory
await sandbox.filesystem.remove('/project/workspace/temp.txt');

Sandbox Management

// Get sandbox info
const info = await sandbox.getInfo();
console.log(info.id, info.provider, info.status);

// Resume existing sandbox
const existing = await compute.sandbox.getById(provider, 'sandbox-id');

// Hibernate sandbox (saves state)
await compute.sandbox.destroy(provider, 'sandbox-id'); // Actually hibernates

// Note: CodeSandbox doesn't support listing all sandboxes
// Each sandbox is managed individually

Best Practices

  1. Resource Management: Use hibernation instead of destroying sandboxes to preserve state
  2. Error Handling: Use try-catch blocks for robust error handling
  3. Timeouts: Set appropriate timeouts for long-running tasks
  4. File Organization: Organize files in /project/workspace/ directory
  5. Template Usage: Use appropriate templates for your project type
  6. API Key Security: Never commit API keys to version control
  7. Snapshot Management: Leverage CodeSandbox's snapshot/resume capabilities

Support

License

MIT