An open-source, faster Devin alternative
TypeScript
Add Mintlify SDK documentation site
motatoesf0b6a0fc77ed
diff --git a/docs/configuration.mdx b/docs/configuration.mdxnew file mode 100644index 00000000..d108b263--- /dev/null+++ b/docs/configuration.mdx@@ -0,0 +1,106 @@+---+title: "Configuration"+description: "Set up API keys, URLs, and environment variables"+---++## Environment Variables++Both SDKs read from these environment variables:++| Variable | Description | Default |+| --- | --- | --- |+| `OPENSANDBOX_API_KEY` | Your API key for authentication | — |+| `OPENSANDBOX_API_URL` | Base URL of the OpenSandbox API | `http://localhost:8080` |++```bash+export OPENSANDBOX_API_KEY="sk-your-api-key"+export OPENSANDBOX_API_URL="https://api.opensandbox.dev"+```++## Inline Configuration++You can also pass credentials directly when creating or connecting to a sandbox:++<CodeGroup>++```typescript TypeScript+import { Sandbox } from 'opensandbox';++const sandbox = await Sandbox.create({+ apiKey: 'sk-your-api-key',+ apiUrl: 'https://api.opensandbox.dev',+ template: 'base',+});+```++```python Python+from opensandbox import Sandbox++sandbox = await Sandbox.create(+ api_key='sk-your-api-key',+ api_url='https://api.opensandbox.dev',+ template='base',+)+```++</CodeGroup>++<Note>+ Inline configuration takes precedence over environment variables.+</Note>++## Authentication++All API requests are authenticated using your API key, sent as the `X-API-Key` header. Both SDKs handle this automatically when you provide the key via environment variable or inline config.++## Architecture: Server vs Combined Mode++OpenSandbox supports two deployment modes that affect how SDKs connect:++### Combined Mode (Default for Local Development)++In combined mode, a single process handles both the control plane and sandbox execution. The SDK talks to one URL for everything.++```+SDK → API Server (creates sandbox + runs commands)+```++### Server Mode (Production)++In server mode, the control plane and workers are separate. When you create a sandbox, the API returns a `connectURL` and `token`. The SDK then communicates directly with the worker for all data operations (commands, files, PTY).++```+SDK → Control Plane (creates sandbox, gets connectURL + token)+SDK → Worker (commands, files, PTY via connectURL)+```++This is handled transparently by the SDK — you don't need to change your code between modes.++## Sandbox Options++Full list of options available when creating a sandbox:++<CodeGroup>++```typescript TypeScript+interface SandboxOpts {+ template?: string; // Container template (default: 'base')+ timeout?: number; // Sandbox TTL in seconds (default: 300)+ apiKey?: string; // API key override+ apiUrl?: string; // API URL override+ envs?: Record<string, string>; // Environment variables for the sandbox+ metadata?: Record<string, string>; // Arbitrary key-value metadata+}+```++```python Python+# Sandbox.create() parameters+template: str = 'base' # Container template+timeout: int = 300 # Sandbox TTL in seconds+api_key: str | None = None # API key override+api_url: str | None = None # API URL override+envs: dict[str, str] | None = None # Environment variables for the sandbox+metadata: dict[str, str] | None = None # Arbitrary key-value metadata+```++</CodeGroup>diff --git a/docs/images/favicon.svg b/docs/images/favicon.svgnew file mode 100644index 00000000..6bd25645--- /dev/null+++ b/docs/images/favicon.svg@@ -0,0 +1,7 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">+ <rect width="32" height="32" rx="6" fill="#6366F1"/>+ <path d="M8 12L16 7L24 12V20L16 25L8 20V12Z" stroke="white" stroke-width="2" fill="none"/>+ <path d="M16 7V25" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <path d="M8 12L24 20" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <path d="M24 12L8 20" stroke="white" stroke-width="1.5" opacity="0.5"/>+</svg>diff --git a/docs/images/logo-dark.svg b/docs/images/logo-dark.svgnew file mode 100644index 00000000..c757836d--- /dev/null+++ b/docs/images/logo-dark.svg@@ -0,0 +1,8 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 32" fill="none">+ <rect width="32" height="32" rx="6" fill="#6366F1"/>+ <path d="M8 12L16 7L24 12V20L16 25L8 20V12Z" stroke="white" stroke-width="2" fill="none"/>+ <path d="M16 7V25" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <path d="M8 12L24 20" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <path d="M24 12L8 20" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <text x="40" y="22" font-family="system-ui, sans-serif" font-size="16" font-weight="700" fill="#F8FAFC">OpenSandbox</text>+</svg>diff --git a/docs/images/logo-light.svg b/docs/images/logo-light.svgnew file mode 100644index 00000000..b74d7c80--- /dev/null+++ b/docs/images/logo-light.svg@@ -0,0 +1,8 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 32" fill="none">+ <rect width="32" height="32" rx="6" fill="#6366F1"/>+ <path d="M8 12L16 7L24 12V20L16 25L8 20V12Z" stroke="white" stroke-width="2" fill="none"/>+ <path d="M16 7V25" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <path d="M8 12L24 20" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <path d="M24 12L8 20" stroke="white" stroke-width="1.5" opacity="0.5"/>+ <text x="40" y="22" font-family="system-ui, sans-serif" font-size="16" font-weight="700" fill="#0F172A">OpenSandbox</text>+</svg>diff --git a/docs/introduction.mdx b/docs/introduction.mdxnew file mode 100644index 00000000..ff1b0a94--- /dev/null+++ b/docs/introduction.mdx@@ -0,0 +1,83 @@+---+title: "Introduction"+description: "Secure cloud sandboxes for AI agents and developers"+---++# OpenSandbox++OpenSandbox gives you **secure, isolated cloud sandboxes** that spin up in milliseconds. Run untrusted code, build AI agent tooling, or create interactive development environments — all within containerized sandboxes you fully control.++## Why OpenSandbox?++<CardGroup cols={2}>+ <Card title="Fast Startup" icon="bolt">+ Sandboxes boot in under a second. Your agents and users never wait.+ </Card>+ <Card title="Secure Isolation" icon="shield">+ Every sandbox runs in its own container with strict resource limits and network isolation.+ </Card>+ <Card title="Full Environment" icon="terminal">+ Each sandbox includes a filesystem, command execution, and interactive terminal (PTY) access.+ </Card>+ <Card title="Custom Templates" icon="layer-group">+ Build reusable templates from Dockerfiles with pre-installed tools and dependencies.+ </Card>+</CardGroup>++## SDKs++OpenSandbox provides first-class SDKs for TypeScript and Python with identical API surfaces.++<CodeGroup>++```bash npm+npm install opensandbox+```++```bash pip+pip install opensandbox+```++</CodeGroup>++## Quick Example++<CodeGroup>++```typescript TypeScript+import { Sandbox } from 'opensandbox';++const sandbox = await Sandbox.create({ template: 'base' });++const result = await sandbox.commands.run('echo "Hello from OpenSandbox!"');+console.log(result.stdout); // Hello from OpenSandbox!++await sandbox.kill();+```++```python Python+from opensandbox import Sandbox++async with Sandbox.create(template='base') as sandbox:+ result = await sandbox.commands.run('echo "Hello from OpenSandbox!"')+ print(result.stdout) # Hello from OpenSandbox!+```++</CodeGroup>++## Next Steps++<CardGroup cols={2}>+ <Card title="Quickstart" icon="rocket" href="/quickstart">+ Get up and running in 5 minutes.+ </Card>+ <Card title="Configuration" icon="gear" href="/configuration">+ Set up API keys and environment variables.+ </Card>+ <Card title="TypeScript SDK" icon="js" href="/sdks/typescript/overview">+ Full TypeScript/JavaScript SDK reference.+ </Card>+ <Card title="Python SDK" icon="python" href="/sdks/python/overview">+ Full Python SDK reference.+ </Card>+</CardGroup>diff --git a/docs/mint.json b/docs/mint.jsonnew file mode 100644index 00000000..4f515036--- /dev/null+++ b/docs/mint.json@@ -0,0 +1,97 @@+{+ "$schema": "https://mintlify.com/docs.json",+ "theme": "maple",+ "name": "OpenSandbox",+ "description": "Secure cloud sandboxes for AI agents and developers",+ "colors": {+ "primary": "#6366F1",+ "light": "#818CF8",+ "dark": "#4F46E5"+ },+ "favicon": "/images/favicon.svg",+ "logo": {+ "light": "/images/logo-light.svg",+ "dark": "/images/logo-dark.svg",+ "href": "https://opensandbox.dev"+ },+ "navbar": {+ "links": [+ {+ "label": "GitHub",+ "href": "https://github.com/nicholasgriffintn/opensandbox"+ }+ ],+ "primary": {+ "type": "button",+ "label": "Get Started",+ "href": "/quickstart"+ }+ },+ "navigation": {+ "tabs": [+ {+ "tab": "Documentation",+ "icon": "book",+ "groups": [+ {+ "group": "Getting Started",+ "pages": [+ "introduction",+ "quickstart",+ "configuration"+ ]+ }+ ]+ },+ {+ "tab": "TypeScript SDK",+ "icon": "js",+ "groups": [+ {+ "group": "Overview",+ "pages": [+ "sdks/typescript/overview"+ ]+ },+ {+ "group": "API Reference",+ "pages": [+ "sdks/typescript/sandbox",+ "sdks/typescript/commands",+ "sdks/typescript/filesystem",+ "sdks/typescript/pty",+ "sdks/typescript/templates"+ ]+ }+ ]+ },+ {+ "tab": "Python SDK",+ "icon": "python",+ "groups": [+ {+ "group": "Overview",+ "pages": [+ "sdks/python/overview"+ ]+ },+ {+ "group": "API Reference",+ "pages": [+ "sdks/python/sandbox",+ "sdks/python/commands",+ "sdks/python/filesystem",+ "sdks/python/pty",+ "sdks/python/templates"+ ]+ }+ ]+ }+ ]+ },+ "footer": {+ "socials": {+ "github": "https://github.com/nicholasgriffintn/opensandbox"+ }+ }+}diff --git a/docs/quickstart.mdx b/docs/quickstart.mdxnew file mode 100644index 00000000..2b5ef056--- /dev/null+++ b/docs/quickstart.mdx@@ -0,0 +1,138 @@+---+title: "Quickstart"+description: "Get up and running with OpenSandbox in 5 minutes"+---++## 1. Install the SDK++<CodeGroup>++```bash npm+npm install opensandbox+```++```bash pip+pip install opensandbox+```++</CodeGroup>++## 2. Set Your API Key++<CodeGroup>++```bash TypeScript+export OPENSANDBOX_API_KEY="your-api-key"+export OPENSANDBOX_API_URL="https://api.opensandbox.dev" # optional, defaults to localhost+```++```bash Python+export OPENSANDBOX_API_KEY="your-api-key"+export OPENSANDBOX_API_URL="https://api.opensandbox.dev" # optional, defaults to localhost+```++</CodeGroup>++Or pass credentials directly when creating a sandbox — see [Configuration](/configuration).++## 3. Create a Sandbox++<CodeGroup>++```typescript TypeScript+import { Sandbox } from 'opensandbox';++const sandbox = await Sandbox.create({+ template: 'base',+ timeout: 300,+});++console.log(`Sandbox created: ${sandbox.sandboxId}`);+```++```python Python+from opensandbox import Sandbox++sandbox = await Sandbox.create(template='base', timeout=300)+print(f"Sandbox created: {sandbox.sandbox_id}")+```++</CodeGroup>++## 4. Run a Command++<CodeGroup>++```typescript TypeScript+const result = await sandbox.commands.run('echo "Hello, World!"');++console.log(result.stdout); // Hello, World!+console.log(result.exitCode); // 0+```++```python Python+result = await sandbox.commands.run('echo "Hello, World!"')++print(result.stdout) # Hello, World!+print(result.exit_code) # 0+```++</CodeGroup>++## 5. Read and Write Files++<CodeGroup>++```typescript TypeScript+// Write a file+await sandbox.files.write('/tmp/hello.txt', 'Hello from OpenSandbox!');++// Read it back+const content = await sandbox.files.read('/tmp/hello.txt');+console.log(content); // Hello from OpenSandbox!++// List a directory+const entries = await sandbox.files.list('/tmp');+entries.forEach(e => console.log(`${e.isDir ? 'd' : 'f'} ${e.name}`));+```++```python Python+# Write a file+await sandbox.files.write('/tmp/hello.txt', 'Hello from OpenSandbox!')++# Read it back+content = await sandbox.files.read('/tmp/hello.txt')+print(content) # Hello from OpenSandbox!++# List a directory+entries = await sandbox.files.list('/tmp')+for e in entries:+ print(f"{'d' if e.is_dir else 'f'} {e.name}")+```++</CodeGroup>++## 6. Clean Up++<CodeGroup>++```typescript TypeScript+await sandbox.kill();+```++```python Python+await sandbox.kill()++# Or use the context manager for automatic cleanup:+async with Sandbox.create() as sandbox:+ # sandbox is automatically killed when the block exits+ result = await sandbox.commands.run('whoami')+```++</CodeGroup>++## Next Steps++- [TypeScript SDK Reference](/sdks/typescript/overview) — full API docs for the TypeScript SDK+- [Python SDK Reference](/sdks/python/overview) — full API docs for the Python SDK+- [Configuration](/configuration) — API keys, URLs, and environment setupdiff --git a/docs/sdks/python/commands.mdx b/docs/sdks/python/commands.mdxnew file mode 100644index 00000000..f338b547--- /dev/null+++ b/docs/sdks/python/commands.mdx@@ -0,0 +1,87 @@+---+title: "Commands"+description: "Execute shell commands inside a sandbox"+---++The `Commands` module lets you run shell commands inside a sandbox and capture their output. Access it via `sandbox.commands`.++## Running a Command++```python+result = await sandbox.commands.run('echo "Hello, World!"')++print(result.stdout) # Hello, World!+print(result.stderr) # (empty)+print(result.exit_code) # 0+```++### `await sandbox.commands.run(command, **kwargs)`++Executes a shell command and waits for it to complete.++<ParamField body="command" type="str" required>+ The shell command to execute.+</ParamField>+<ParamField body="timeout" type="int" default="60">+ Maximum execution time in seconds. The command is killed if it exceeds this.+</ParamField>+<ParamField body="env" type="dict[str, str] | None" default="None">+ Additional environment variables for this command.+</ParamField>+<ParamField body="cwd" type="str | None" default="None">+ Working directory for the command.+</ParamField>++**Returns:** `ProcessResult`++## ProcessResult++`ProcessResult` is a dataclass with the following fields:++| Field | Type | Description |+| --- | --- | --- |+| `exit_code` | `int` | Exit code of the process (0 = success) |+| `stdout` | `str` | Standard output |+| `stderr` | `str` | Standard error |++## Examples++### Run with a Custom Working Directory++```python+result = await sandbox.commands.run('ls -la', cwd='/app')+```++### Run with Environment Variables++```python+result = await sandbox.commands.run(+ 'echo $MY_VAR',+ env={'MY_VAR': 'hello'},+)+print(result.stdout) # hello+```++### Run with a Timeout++```python+result = await sandbox.commands.run('sleep 30', timeout=5)+print(result.exit_code) # non-zero (killed)+```++### Check for Errors++```python+result = await sandbox.commands.run('python3 script.py')++if result.exit_code != 0:+ print(f"Command failed: {result.stderr}")+```++### Chain Commands++```python+result = await sandbox.commands.run(+ 'cd /app && pip install -r requirements.txt && python3 main.py'+)+```diff --git a/docs/sdks/python/filesystem.mdx b/docs/sdks/python/filesystem.mdxnew file mode 100644index 00000000..53175047--- /dev/null+++ b/docs/sdks/python/filesystem.mdx@@ -0,0 +1,159 @@+---+title: "Filesystem"+description: "Read, write, and manage files inside a sandbox"+---++The `Filesystem` module provides full file I/O within a sandbox. Access it via `sandbox.files`.++## Reading Files++### `await sandbox.files.read(path)`++Reads a file as a UTF-8 string.++```python+content = await sandbox.files.read('/app/config.json')+config = json.loads(content)+```++<ParamField body="path" type="str" required>+ Absolute path to the file.+</ParamField>++**Returns:** `str`++### `await sandbox.files.read_bytes(path)`++Reads a file as raw bytes.++```python+data = await sandbox.files.read_bytes('/app/image.png')+print(f"File size: {len(data)} bytes")+```++<ParamField body="path" type="str" required>+ Absolute path to the file.+</ParamField>++**Returns:** `bytes`++## Writing Files++### `await sandbox.files.write(path, content)`++Writes a string or bytes to a file. Creates parent directories if needed.++```python+# Write text+await sandbox.files.write('/app/hello.txt', 'Hello, World!')++# Write binary+await sandbox.files.write('/app/data.bin', b'\x00\x01\x02')+```++<ParamField body="path" type="str" required>+ Absolute path to the file.+</ParamField>+<ParamField body="content" type="str | bytes" required>+ File content to write.+</ParamField>++**Returns:** `None`++## Listing Directories++### `await sandbox.files.list(path)`++Lists the contents of a directory.++```python+entries = await sandbox.files.list('/app')++for entry in entries:+ kind = 'd' if entry.is_dir else 'f'+ print(f"{kind} {entry.name} ({entry.size} bytes)")+```++<ParamField body="path" type="str" default="/">+ Directory path to list.+</ParamField>++**Returns:** `list[EntryInfo]`++### EntryInfo++`EntryInfo` is a dataclass:++| Field | Type | Description |+| --- | --- | --- |+| `name` | `str` | File or directory name |+| `is_dir` | `bool` | `True` if this entry is a directory |+| `path` | `str` | Full path to the entry |+| `size` | `int` | Size in bytes (0 for directories) |++## Managing Files and Directories++### `await sandbox.files.make_dir(path)`++Creates a directory and any necessary parent directories.++```python+await sandbox.files.make_dir('/app/src/components')+```++<ParamField body="path" type="str" required>+ Directory path to create.+</ParamField>++**Returns:** `None`++### `await sandbox.files.remove(path)`++Deletes a file or directory.++```python+await sandbox.files.remove('/app/temp.txt')+```++<ParamField body="path" type="str" required>+ Path to remove.+</ParamField>++**Returns:** `None`++### `await sandbox.files.exists(path)`++Checks whether a file or directory exists.++```python+if await sandbox.files.exists('/app/requirements.txt'):+ print('Python project detected')+```++<ParamField body="path" type="str" required>+ Path to check.+</ParamField>++**Returns:** `bool`++## Examples++### Upload and Run a Script++```python+await sandbox.files.write('/tmp/setup.sh', """#!/bin/bash+echo "Running setup..."+apt-get update -qq+echo "Done!"+""")++result = await sandbox.commands.run('bash /tmp/setup.sh')+print(result.stdout)+```++### Copy Files Between Paths++```python+content = await sandbox.files.read_bytes('/app/original.dat')+await sandbox.files.write('/backup/original.dat', content)+```diff --git a/docs/sdks/python/overview.mdx b/docs/sdks/python/overview.mdxnew file mode 100644index 00000000..27c14cf5--- /dev/null+++ b/docs/sdks/python/overview.mdx@@ -0,0 +1,64 @@+---+title: "Python SDK"+description: "Full reference for the OpenSandbox Python SDK"+---++## Installation++```bash+pip install opensandbox+```++**Requirements:** Python 3.10+++**Dependencies:** `httpx>=0.27.0`, `websockets>=12.0`++## Overview++The Python SDK is fully async and provides the same modules as the TypeScript SDK:++| Module | Access | Purpose |+| --- | --- | --- |+| [Sandbox](/sdks/python/sandbox) | `Sandbox.create()` | Create, connect to, and manage sandboxes |+| [Commands](/sdks/python/commands) | `sandbox.commands` | Execute shell commands |+| [Filesystem](/sdks/python/filesystem) | `sandbox.files` | Read, write, and manage files |+| [PTY](/sdks/python/pty) | `sandbox.pty` | Interactive terminal sessions |+| [Templates](/sdks/python/templates) | `sandbox.templates` | Build and manage container templates |++## Quick Example++```python+import asyncio+from opensandbox import Sandbox++async def main():+ async with Sandbox.create(template='base') as sandbox:+ # Run a command+ result = await sandbox.commands.run('python3 --version')+ print(result.stdout)++ # Work with files+ await sandbox.files.write('/app/main.py', 'print("hello")')+ output = await sandbox.commands.run('python3 /app/main.py')+ print(output.stdout) # hello++asyncio.run(main())+```++<Note>+ All SDK operations are async. Use `async with` for automatic cleanup, or call `await sandbox.kill()` manually.+</Note>++## Exports++```python+from opensandbox import (+ Sandbox,+ Filesystem,+ Commands,+ ProcessResult,+ Pty,+ PtySession,+ Template,+)+```diff --git a/docs/sdks/python/pty.mdx b/docs/sdks/python/pty.mdxnew file mode 100644index 00000000..a824259e--- /dev/null+++ b/docs/sdks/python/pty.mdx@@ -0,0 +1,81 @@+---+title: "PTY"+description: "Interactive terminal sessions inside a sandbox"+---++The `Pty` module provides interactive pseudo-terminal (PTY) sessions over WebSocket. Access it via `sandbox.pty`.++## Creating a PTY Session++```python+session = await sandbox.pty.create(+ cols=120,+ rows=40,+ on_output=lambda data: print(data.decode(), end=''),+)+```++### `await sandbox.pty.create(**kwargs)`++Opens a new interactive terminal session.++<ParamField body="cols" type="int" default="80">+ Terminal width in columns.+</ParamField>+<ParamField body="rows" type="int" default="24">+ Terminal height in rows.+</ParamField>+<ParamField body="on_output" type="Callable[[bytes], None] | None" default="None">+ Callback invoked when the terminal produces output.+</ParamField>++**Returns:** `PtySession`++## PtySession++`PtySession` is a dataclass with the following interface:++| Property / Method | Type | Description |+| --- | --- | --- |+| `session_id` | `str` | Unique session identifier |+| `sandbox_id` | `str` | ID of the parent sandbox |+| `send(data)` | `async (str \| bytes) -> None` | Send input to the terminal |+| `recv()` | `async () -> bytes` | Receive output from the terminal |+| `close()` | `async () -> None` | Close the PTY session |++## Examples++### Run an Interactive Command++```python+session = await sandbox.pty.create(+ on_output=lambda data: print(data.decode(), end=''),+)++# Type a command+await session.send('ls -la\n')++# Wait for output+import asyncio+await asyncio.sleep(2)++await session.close()+```++### Manual Receive Loop++```python+session = await sandbox.pty.create()++await session.send('echo "hello"\n')++# Read output manually+data = await session.recv()+print(data.decode())++await session.close()+```++<Note>+ PTY sessions use WebSocket connections under the hood. Each session maintains a persistent connection to the sandbox worker.+</Note>diff --git a/docs/sdks/python/sandbox.mdx b/docs/sdks/python/sandbox.mdxnew file mode 100644index 00000000..c8e0087f--- /dev/null+++ b/docs/sdks/python/sandbox.mdx@@ -0,0 +1,139 @@+---+title: "Sandbox"+description: "Create, connect to, and manage sandbox lifecycles"+---++The `Sandbox` class is the main entry point to OpenSandbox. It supports both manual lifecycle management and async context managers.++## Creating a Sandbox++```python+from opensandbox import Sandbox++sandbox = await Sandbox.create(+ template='base',+ timeout=300,+ envs={'NODE_ENV': 'production'},+ metadata={'owner': 'my-agent'},+)+```++### `Sandbox.create(**kwargs)`++Creates a new sandbox and returns a connected `Sandbox` instance.++<ParamField body="template" type="str" default="base">+ Container template to use.+</ParamField>+<ParamField body="timeout" type="int" default="300">+ Sandbox time-to-live in seconds.+</ParamField>+<ParamField body="api_key" type="str | None" default="None">+ API key. Falls back to `OPENSANDBOX_API_KEY` env var.+</ParamField>+<ParamField body="api_url" type="str | None" default="None">+ API base URL. Falls back to `OPENSANDBOX_API_URL` env var, then `http://localhost:8080`.+</ParamField>+<ParamField body="envs" type="dict[str, str] | None" default="None">+ Environment variables injected into the sandbox.+</ParamField>+<ParamField body="metadata" type="dict[str, str] | None" default="None">+ Arbitrary key-value metadata attached to the sandbox.+</ParamField>++**Returns:** `Sandbox`++## Async Context Manager++The recommended way to use sandboxes in Python — the sandbox is automatically killed when the block exits:++```python+async with Sandbox.create(template='base') as sandbox:+ result = await sandbox.commands.run('echo "hello"')+ print(result.stdout)+# sandbox is automatically killed here+```++## Connecting to an Existing Sandbox++```python+sandbox = await Sandbox.connect(+ 'sandbox-abc123',+ api_key='sk-...',+)+```++### `Sandbox.connect(sandbox_id, **kwargs)`++Connects to a running sandbox by ID.++<ParamField body="sandbox_id" type="str" required>+ The ID of the sandbox to connect to.+</ParamField>+<ParamField body="api_key" type="str | None" default="None">+ API key override.+</ParamField>+<ParamField body="api_url" type="str | None" default="None">+ API URL override.+</ParamField>++**Returns:** `Sandbox`++## Properties++| Property | Type | Description |+| --- | --- | --- |+| `sandbox_id` | `str` | Unique identifier for the sandbox |+| `status` | `str` | Current status: `"running"`, `"stopped"`, or `"error"` |+| `template` | `str` | Template used to create the sandbox |+| `files` | `Filesystem` | [Filesystem](/sdks/python/filesystem) operations |+| `commands` | `Commands` | [Command](/sdks/python/commands) execution |+| `pty` | `Pty` | [PTY](/sdks/python/pty) terminal access |++## Instance Methods++### `await sandbox.kill()`++Stops and destroys the sandbox.++```python+await sandbox.kill()+```++**Returns:** `None`++### `await sandbox.is_running()`++Checks if the sandbox is still alive.++```python+if not await sandbox.is_running():+ print('Sandbox has stopped')+```++**Returns:** `bool`++### `await sandbox.set_timeout(timeout)`++Updates the sandbox timeout. Resets the TTL countdown.++```python+# Extend for another 10 minutes+await sandbox.set_timeout(600)+```++<ParamField body="timeout" type="int" required>+ New timeout in seconds.+</ParamField>++**Returns:** `None`++### `sandbox.close()`++Closes the underlying HTTP client connections without killing the sandbox.++```python+sandbox.close()+```++**Returns:** `None`diff --git a/docs/sdks/python/templates.mdx b/docs/sdks/python/templates.mdxnew file mode 100644index 00000000..939f277f--- /dev/null+++ b/docs/sdks/python/templates.mdx@@ -0,0 +1,107 @@+---+title: "Templates"+description: "Build and manage reusable sandbox templates"+---++Templates let you create reusable sandbox images from Dockerfiles. Pre-install languages, tools, and dependencies so your sandboxes start ready to go.++## Building a Template++```python+from opensandbox import Sandbox++sandbox = await Sandbox.create()++template = await sandbox.templates.build('python-ml', """+FROM ubuntu:22.04+RUN apt-get update && apt-get install -y python3 python3-pip+RUN pip3 install numpy pandas scikit-learn+""")++print(template.template_id) # tpl-abc123+print(template.status) # building → ready+```++### `await sandbox.templates.build(name, dockerfile)`++Builds a new template from a Dockerfile.++<ParamField body="name" type="str" required>+ A unique name for the template.+</ParamField>+<ParamField body="dockerfile" type="str" required>+ The Dockerfile content to build from.+</ParamField>++**Returns:** `TemplateInfo`++## Listing Templates++```python+templates = await sandbox.templates.list()++for t in templates:+ print(f"{t.name} ({t.tag}) — {t.status}")+```++### `await sandbox.templates.list()`++Returns all templates.++**Returns:** `list[TemplateInfo]`++## Getting a Template++```python+template = await sandbox.templates.get('python-ml')+print(template)+```++### `await sandbox.templates.get(name)`++Gets a template by name.++<ParamField body="name" type="str" required>+ Template name.+</ParamField>++**Returns:** `TemplateInfo`++## Deleting a Template++```python+await sandbox.templates.delete('python-ml')+```++### `await sandbox.templates.delete(name)`++Deletes a template by name.++<ParamField body="name" type="str" required>+ Template name to delete.+</ParamField>++**Returns:** `None`++## TemplateInfo++`TemplateInfo` is a dataclass:++| Field | Type | Description |+| --- | --- | --- |+| `template_id` | `str` | Unique template identifier |+| `name` | `str` | Template name |+| `tag` | `str` | Image tag |+| `status` | `str` | Build status: `"building"`, `"ready"`, `"error"` |++## Using a Template++Once built, pass the template name when creating a sandbox:++```python+async with Sandbox.create(template='python-ml') as sandbox:+ result = await sandbox.commands.run(+ 'python3 -c "import numpy; print(numpy.__version__)"'+ )+ print(result.stdout) # 1.24.0+```diff --git a/docs/sdks/typescript/commands.mdx b/docs/sdks/typescript/commands.mdxnew file mode 100644index 00000000..45fc37c9--- /dev/null+++ b/docs/sdks/typescript/commands.mdx@@ -0,0 +1,94 @@+---+title: "Commands"+description: "Execute shell commands inside a sandbox"+---++The `Commands` module lets you run shell commands inside a sandbox and capture their output. Access it via `sandbox.commands`.++## Running a Command++```typescript+const result = await sandbox.commands.run('echo "Hello, World!"');++console.log(result.stdout); // Hello, World!+console.log(result.stderr); // (empty)+console.log(result.exitCode); // 0+```++### `sandbox.commands.run(command, opts?)`++Executes a shell command and waits for it to complete.++<ParamField body="command" type="string" required>+ The shell command to execute.+</ParamField>++<ParamField body="opts" type="RunOpts" optional>+ <Expandable title="properties">+ <ParamField body="timeout" type="number" optional>+ Maximum execution time in seconds. The command is killed if it exceeds this.+ </ParamField>+ <ParamField body="env" type="Record<string, string>" optional>+ Additional environment variables for this command.+ </ParamField>+ <ParamField body="cwd" type="string" optional>+ Working directory for the command.+ </ParamField>+ </Expandable>+</ParamField>++**Returns:** `Promise<ProcessResult>`++## ProcessResult++| Field | Type | Description |+| --- | --- | --- |+| `exitCode` | `number` | Exit code of the process (0 = success) |+| `stdout` | `string` | Standard output |+| `stderr` | `string` | Standard error |++## Examples++### Run with a Custom Working Directory++```typescript+const result = await sandbox.commands.run('ls -la', {+ cwd: '/app',+});+```++### Run with Environment Variables++```typescript+const result = await sandbox.commands.run('echo $MY_VAR', {+ env: { MY_VAR: 'hello' },+});+console.log(result.stdout); // hello+```++### Run with a Timeout++```typescript+const result = await sandbox.commands.run('sleep 30', {+ timeout: 5, // kill after 5 seconds+});+console.log(result.exitCode); // non-zero (killed)+```++### Check for Errors++```typescript+const result = await sandbox.commands.run('python3 script.py');++if (result.exitCode !== 0) {+ console.error(`Command failed: ${result.stderr}`);+}+```++### Chain Commands++```typescript+const result = await sandbox.commands.run(+ 'cd /app && npm install && npm run build'+);+```diff --git a/docs/sdks/typescript/filesystem.mdx b/docs/sdks/typescript/filesystem.mdxnew file mode 100644index 00000000..d4155c93--- /dev/null+++ b/docs/sdks/typescript/filesystem.mdx@@ -0,0 +1,159 @@+---+title: "Filesystem"+description: "Read, write, and manage files inside a sandbox"+---++The `Filesystem` module provides full file I/O within a sandbox. Access it via `sandbox.files`.++## Reading Files++### `sandbox.files.read(path)`++Reads a file as a UTF-8 string.++```typescript+const content = await sandbox.files.read('/app/config.json');+const config = JSON.parse(content);+```++<ParamField body="path" type="string" required>+ Absolute path to the file.+</ParamField>++**Returns:** `Promise<string>`++### `sandbox.files.readBytes(path)`++Reads a file as raw bytes.++```typescript+const bytes = await sandbox.files.readBytes('/app/image.png');+console.log(`File size: ${bytes.length} bytes`);+```++<ParamField body="path" type="string" required>+ Absolute path to the file.+</ParamField>++**Returns:** `Promise<Uint8Array>`++## Writing Files++### `sandbox.files.write(path, content)`++Writes a string or binary content to a file. Creates parent directories if needed.++```typescript+// Write text+await sandbox.files.write('/app/hello.txt', 'Hello, World!');++// Write binary+const encoder = new TextEncoder();+await sandbox.files.write('/app/data.bin', encoder.encode('binary data'));+```++<ParamField body="path" type="string" required>+ Absolute path to the file.+</ParamField>+<ParamField body="content" type="string | Uint8Array" required>+ File content to write.+</ParamField>++**Returns:** `Promise<void>`++## Listing Directories++### `sandbox.files.list(path?)`++Lists the contents of a directory.++```typescript+const entries = await sandbox.files.list('/app');++for (const entry of entries) {+ console.log(`${entry.isDir ? 'DIR ' : 'FILE'} ${entry.name} (${entry.size} bytes)`);+}+```++<ParamField body="path" type="string" default="/">+ Directory path to list.+</ParamField>++**Returns:** `Promise<EntryInfo[]>`++### EntryInfo++| Field | Type | Description |+| --- | --- | --- |+| `name` | `string` | File or directory name |+| `isDir` | `boolean` | `true` if this entry is a directory |+| `path` | `string` | Full path to the entry |+| `size` | `number` | Size in bytes (0 for directories) |++## Managing Files and Directories++### `sandbox.files.makeDir(path)`++Creates a directory and any necessary parent directories.++```typescript+await sandbox.files.makeDir('/app/src/components');+```++<ParamField body="path" type="string" required>+ Directory path to create.+</ParamField>++**Returns:** `Promise<void>`++### `sandbox.files.remove(path)`++Deletes a file or directory.++```typescript+await sandbox.files.remove('/app/temp.txt');+```++<ParamField body="path" type="string" required>+ Path to remove.+</ParamField>++**Returns:** `Promise<void>`++### `sandbox.files.exists(path)`++Checks whether a file or directory exists.++```typescript+if (await sandbox.files.exists('/app/package.json')) {+ console.log('Node.js project detected');+}+```++<ParamField body="path" type="string" required>+ Path to check.+</ParamField>++**Returns:** `Promise<boolean>`++## Examples++### Upload and Run a Script++```typescript+await sandbox.files.write('/tmp/script.sh', `#!/bin/bash+echo "Running setup..."+apt-get update -qq+echo "Done!"+`);++const result = await sandbox.commands.run('bash /tmp/script.sh');+console.log(result.stdout);+```++### Copy Files Between Paths++```typescript+const content = await sandbox.files.readBytes('/app/original.dat');+await sandbox.files.write('/backup/original.dat', content);+```diff --git a/docs/sdks/typescript/overview.mdx b/docs/sdks/typescript/overview.mdxnew file mode 100644index 00000000..fa83b681--- /dev/null+++ b/docs/sdks/typescript/overview.mdx@@ -0,0 +1,75 @@+---+title: "TypeScript SDK"+description: "Full reference for the OpenSandbox TypeScript/JavaScript SDK"+---++## Installation++```bash+npm install opensandbox+```++## Overview++The TypeScript SDK provides five main modules:++| Module | Access | Purpose |+| --- | --- | --- |+| [Sandbox](/sdks/typescript/sandbox) | `Sandbox.create()` | Create, connect to, and manage sandboxes |+| [Commands](/sdks/typescript/commands) | `sandbox.commands` | Execute shell commands |+| [Filesystem](/sdks/typescript/filesystem) | `sandbox.files` | Read, write, and manage files |+| [PTY](/sdks/typescript/pty) | `sandbox.pty` | Interactive terminal sessions |+| [Templates](/sdks/typescript/templates) | `sandbox.templates` | Build and manage container templates |++## Quick Example++```typescript+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++```typescript+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';+```diff --git a/docs/sdks/typescript/pty.mdx b/docs/sdks/typescript/pty.mdxnew file mode 100644index 00000000..6b7478d9--- /dev/null+++ b/docs/sdks/typescript/pty.mdx@@ -0,0 +1,87 @@+---+title: "PTY"+description: "Interactive terminal sessions inside a sandbox"+---++The `Pty` module provides interactive pseudo-terminal (PTY) sessions over WebSocket. Access it via `sandbox.pty`.++## Creating a PTY Session++```typescript+const session = await sandbox.pty.create({+ cols: 120,+ rows: 40,+ onOutput: (data) => {+ process.stdout.write(data);+ },+});+```++### `sandbox.pty.create(opts?)`++Opens a new interactive terminal session.++<ParamField body="opts" type="PtyOpts" optional>+ <Expandable title="properties">+ <ParamField body="cols" type="number" optional>+ Terminal width in columns.+ </ParamField>+ <ParamField body="rows" type="number" optional>+ Terminal height in rows.+ </ParamField>+ <ParamField body="onOutput" type="(data: Uint8Array) => void" optional>+ Callback invoked when the terminal produces output.+ </ParamField>+ </Expandable>+</ParamField>++**Returns:** `Promise<PtySession>`++## PtySession++| Property / Method | Type | Description |+| --- | --- | --- |+| `sessionId` | `string` | Unique session identifier |+| `send(data)` | `(data: string \| Uint8Array) => void` | Send input to the terminal |+| `close()` | `() => void` | Close the PTY session |++## Examples++### Run an Interactive Command++```typescript+const session = await sandbox.pty.create({+ onOutput: (data) => {+ const text = new TextDecoder().decode(data);+ process.stdout.write(text);+ },+});++// Type a command+session.send('ls -la\n');++// Wait a moment for output, then close+setTimeout(() => session.close(), 2000);+```++### Pipe User Input++```typescript+const session = await sandbox.pty.create({+ cols: 80,+ rows: 24,+ onOutput: (data) => {+ process.stdout.write(new TextDecoder().decode(data));+ },+});++// Forward stdin to the PTY+process.stdin.setRawMode(true);+process.stdin.on('data', (chunk) => {+ session.send(chunk);+});+```++<Note>+ PTY sessions use WebSocket connections under the hood. Each session maintains a persistent connection to the sandbox worker.+</Note>diff --git a/docs/sdks/typescript/sandbox.mdx b/docs/sdks/typescript/sandbox.mdxnew file mode 100644index 00000000..e7b537fd--- /dev/null+++ b/docs/sdks/typescript/sandbox.mdx@@ -0,0 +1,127 @@+---+title: "Sandbox"+description: "Create, connect to, and manage sandbox lifecycles"+---++The `Sandbox` class is the main entry point to OpenSandbox. Use it to create new sandboxes, connect to existing ones, and access all sub-modules (commands, filesystem, PTY, templates).++## Creating a Sandbox++```typescript+import { Sandbox } from 'opensandbox';++const sandbox = await Sandbox.create({+ template: 'base',+ timeout: 300,+ envs: { NODE_ENV: 'production' },+ metadata: { owner: 'my-agent' },+});+```++### `Sandbox.create(opts?)`++Creates a new sandbox and returns a connected `Sandbox` instance.++<ParamField body="opts" type="SandboxOpts" optional>+ <Expandable title="properties">+ <ParamField body="template" type="string" default="base">+ Container template to use.+ </ParamField>+ <ParamField body="timeout" type="number" default="300">+ Sandbox time-to-live in seconds.+ </ParamField>+ <ParamField body="apiKey" type="string" optional>+ API key. Falls back to `OPENSANDBOX_API_KEY` env var.+ </ParamField>+ <ParamField body="apiUrl" type="string" optional>+ API base URL. Falls back to `OPENSANDBOX_API_URL` env var, then `http://localhost:8080`.+ </ParamField>+ <ParamField body="envs" type="Record<string, string>" optional>+ Environment variables injected into the sandbox.+ </ParamField>+ <ParamField body="metadata" type="Record<string, string>" optional>+ Arbitrary key-value metadata attached to the sandbox.+ </ParamField>+ </Expandable>+</ParamField>++**Returns:** `Promise<Sandbox>`++## Connecting to an Existing Sandbox++```typescript+const sandbox = await Sandbox.connect('sandbox-abc123', {+ apiKey: 'sk-...',+});+```++### `Sandbox.connect(sandboxId, opts?)`++Connects to a running sandbox by ID.++<ParamField body="sandboxId" type="string" required>+ The ID of the sandbox to connect to.+</ParamField>++<ParamField body="opts" type="object" optional>+ <Expandable title="properties">+ <ParamField body="apiKey" type="string" optional>+ API key override.+ </ParamField>+ <ParamField body="apiUrl" type="string" optional>+ API URL override.+ </ParamField>+ </Expandable>+</ParamField>++**Returns:** `Promise<Sandbox>`++## Properties++| Property | Type | Description |+| --- | --- | --- |+| `sandboxId` | `string` | Unique identifier for the sandbox |+| `status` | `string` | Current status: `"running"`, `"stopped"`, or `"error"` |+| `files` | `Filesystem` | [Filesystem](/sdks/typescript/filesystem) operations |+| `commands` | `Commands` | [Command](/sdks/typescript/commands) execution |+| `pty` | `Pty` | [PTY](/sdks/typescript/pty) terminal access |++## Instance Methods++### `sandbox.kill()`++Stops and destroys the sandbox. All data is lost.++```typescript+await sandbox.kill();+```++**Returns:** `Promise<void>`++### `sandbox.isRunning()`++Checks if the sandbox is still alive.++```typescript+const alive = await sandbox.isRunning();+if (!alive) {+ console.log('Sandbox has stopped');+}+```++**Returns:** `Promise<boolean>`++### `sandbox.setTimeout(timeout)`++Updates the sandbox timeout. Resets the TTL countdown.++```typescript+// Extend the sandbox for another 10 minutes+await sandbox.setTimeout(600);+```++<ParamField body="timeout" type="number" required>+ New timeout in seconds.+</ParamField>++**Returns:** `Promise<void>`diff --git a/docs/sdks/typescript/templates.mdx b/docs/sdks/typescript/templates.mdxnew file mode 100644index 00000000..f7fb75d9--- /dev/null+++ b/docs/sdks/typescript/templates.mdx@@ -0,0 +1,105 @@+---+title: "Templates"+description: "Build and manage reusable sandbox templates"+---++Templates let you create reusable sandbox images from Dockerfiles. Pre-install languages, tools, and dependencies so your sandboxes start ready to go.++## Building a Template++```typescript+import { Sandbox } from 'opensandbox';++const sandbox = await Sandbox.create();++const template = await sandbox.templates.build('python-ml', `+FROM ubuntu:22.04+RUN apt-get update && apt-get install -y python3 python3-pip+RUN pip3 install numpy pandas scikit-learn+`);++console.log(template.templateID); // tpl-abc123+console.log(template.status); // building → ready+```++### `sandbox.templates.build(name, dockerfile)`++Builds a new template from a Dockerfile.++<ParamField body="name" type="string" required>+ A unique name for the template.+</ParamField>+<ParamField body="dockerfile" type="string" required>+ The Dockerfile content to build from.+</ParamField>++**Returns:** `Promise<TemplateInfo>`++## Listing Templates++```typescript+const templates = await sandbox.templates.list();++for (const t of templates) {+ console.log(`${t.name} (${t.tag}) — ${t.status}`);+}+```++### `sandbox.templates.list()`++Returns all templates.++**Returns:** `Promise<TemplateInfo[]>`++## Getting a Template++```typescript+const template = await sandbox.templates.get('python-ml');+console.log(template);+```++### `sandbox.templates.get(name)`++Gets a template by name.++<ParamField body="name" type="string" required>+ Template name.+</ParamField>++**Returns:** `Promise<TemplateInfo>`++## Deleting a Template++```typescript+await sandbox.templates.delete('python-ml');+```++### `sandbox.templates.delete(name)`++Deletes a template by name.++<ParamField body="name" type="string" required>+ Template name to delete.+</ParamField>++**Returns:** `Promise<void>`++## TemplateInfo++| Field | Type | Description |+| --- | --- | --- |+| `templateID` | `string` | Unique template identifier |+| `name` | `string` | Template name |+| `tag` | `string` | Image tag |+| `status` | `string` | Build status: `"building"`, `"ready"`, `"error"` |++## Using a Template++Once built, pass the template name when creating a sandbox:++```typescript+const sandbox = await Sandbox.create({ template: 'python-ml' });++const result = await sandbox.commands.run('python3 -c "import numpy; print(numpy.__version__)"');+console.log(result.stdout); // 1.24.0+```