Skip to main content

Installation

pip install opencomputer
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
TemplatesTemplate(api_url, api_key)Build and manage container templates

Quick Example

import asyncio
from opencomputer import Sandbox

async def main():
    sandbox = await Sandbox.create(template='base')

    # 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

    await sandbox.kill()
    await sandbox.close()

asyncio.run(main())
All SDK operations are async. Call await sandbox.kill() to stop the sandbox and await sandbox.close() to clean up the HTTP client.

Exports

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