Skip to main content

Installation

npm install opensandbox

Overview

The TypeScript SDK provides five main modules:
ModuleAccessPurpose
SandboxSandbox.create()Create, connect to, and manage sandboxes
Commandssandbox.commandsExecute shell commands
Filesystemsandbox.filesRead, write, and manage files
PTYsandbox.ptyInteractive terminal sessions
Templatessandbox.templatesBuild and manage container templates

Quick Example

import { Sandbox } from 'opensandbox';

// Create a sandbox
const sandbox = await Sandbox.create({ template: 'base' });

// Run a command
const result = await sandbox.commands.run('node --version');
console.log(result.stdout);

// Work with files
await sandbox.files.write('/app/index.js', 'console.log("hello")');
const output = await sandbox.commands.run('node /app/index.js');
console.log(output.stdout); // hello

// Clean up
await sandbox.kill();

Exports

import {
  Sandbox,
  type SandboxOpts,
} from 'opensandbox';

// Also available:
import {
  Filesystem,
  type EntryInfo,
} from 'opensandbox';

import {
  Commands,
  type ProcessResult,
  type RunOpts,
} from 'opensandbox';

import {
  Pty,
  type PtySession,
  type PtyOpts,
} from 'opensandbox';

import {
  Templates,
  type TemplateInfo,
} from 'opensandbox';