Skip to main content

Installation

pip install opensandbox-sdk
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:
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 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())
All SDK operations are async. Use async with for automatic cleanup, or call await sandbox.kill() manually.

Exports

from opensandbox import (
    Sandbox,
    Filesystem,
    Commands,
    ProcessResult,
    Pty,
    PtySession,
    Template,
)