OpenComputer Documentation

repository·main·Indexed 19 days ago

https://github.com/diggerhq/opencomputer

A platform for sandboxed execution environments focused on developer hosting and agentic workflows. It includes an SDK, a CLI for managing agent repositories and deployments, and a gateway for proxying requests to OpenRouter with built-in budget enforcement and spend tracking. The documentation covers TTI (Time-to-Interactive) benchmarking, agent repository structure, local and remote session management, and D1 database migration workflows.

Tokens
275.1K
Snippets
852
Records
1.3K
Agent score
65%

What's inside OpenComputer

  1. Overview of OpenComputer SDK Modules

    main

    The @opencomputer/sdk is organized into several functional modules. Depending on your use case, you will interact with one or more of the following:

    • Sandbox: Create, connect, and manage the sandbox lifecycle.
    • Usage & Tags: Query usage, group by tag, and manage sandbox tags.
    • Exec: Run commands and manage execution sessions.
    • Sandbox agent: Start and manage an agent session inside a sandbox (Note: This is a low-level module and is deprecated).
    • Filesystem: Read, write, and manage files within the sandbox.
    • PTY: Manage interactive terminal sessions.
    • Image: Use the declarative sandbox image builder.
    • Snapshots: Access and manage pre-built sandbox environments.
    • Secret Stores: Manage secrets and egress control.
  2. Overview of Durable Agent Sessions

    main

    Durable Agent Sessions allow you to define an agent and run resumable, steerable sessions. You can create an agent, start a session, stream its event log, steer it with messages, and receive results via webhooks.

    Key capabilities include:

    • Runtime Supervision: Automatic restarts on crashes, hibernation for idle sessions, and clean stops for hung runs.
    • Sandboxing: Separation of the Brain (agent loop) and Hands (files and commands). Untrusted work is contained in the hands sandbox, while model keys are kept secure in a secret store outside the sandbox.
    • Live Interaction: Stream events using a session token and reconnect from any seq without gaps. You can send follow-up messages without exposing your organization key.
    • Webhook Delivery: User-level events are delivered via signed Standard Webhooks with retries and dead-lettering support.
  3. Overview of OpenComputer Python SDK modules

    main

    The OpenComputer Python SDK is organized into several specialized modules for managing sandboxes and their environments:

    • Sandbox: Create, connect, and manage the sandbox lifecycle.
    • Exec: Run commands and manage execution sessions.
    • Agent: Start and manage Claude agent sessions.
    • Filesystem: Read, write, and manage files within the sandbox.
    • PTY: Handle interactive terminal sessions.
    • Image: Use the declarative sandbox image builder.
    • Snapshots: Access and use pre-built sandbox environments.
    • Secret Stores: Manage secrets and egress control.
  4. What is OpenComputer?

    main

    OpenComputer provides cloud-based Linux VMs designed for AI applications. Unlike containers, these are full virtual machines with their own kernel, memory, and disk, utilizing KVM for hardware-level isolation.

    Key features include:

    • Long-running environments: Sandboxes persist for hours or days, allowing for package installation and project builds without cold starts.
    • Checkpoint & fork: You can create named snapshots of a VM and fork from them, allowing you to run multiple parallel approaches from a single state.
    • Elastic compute: You can scale CPU and memory resources at runtime to handle heavy tasks and release them when finished.
  5. Use the default sandbox template

    main

    If no image or snapshot is specified when creating a sandbox, the system uses a default template containing:

    • OS: Ubuntu 22.04
    • Languages: Python 3 (with pip, venv, setuptools), Node.js 20 LTS (with npm)
    • Build Tools: build-essential, cmake, pkg-config
    • CLI Tools: git, git-lfs, curl, wget, jq, rsync, htop, tree
    • Editors: nano, vim-tiny
    • Database: sqlite3
    • Networking: openssh-client, iproute2, net-tools, dnsutils
    • Agent Support: Claude Agent SDK and claude-code (pre-installed for agent sessions)
  6. What is an Agent in OpenComputer

    main

    In OpenComputer, an agent is a configuration object, not a compute instance. It defines the agent's knowledge (prompt, skills), its drivers (runtime, model), its triggers, its policies, and its connection (the scope of repositories it can act upon).

    Key characteristics:

    • Decoupled from compute: An agent defines what to do, but it does not run itself. Instead, sessions reference an agent to perform work.
    • Repo-agnostic: An agent is not bound to a single repository. Its connection defines a candidate set of repositories. At runtime, a session resolves which specific repository to work in based on the trigger, the conversation, an optional repo default, or user input.
    • Immutable Versions: Every change to an agent (config, deployment, or model switch) creates a new immutable version. Sessions are pinned to the version they started with; updates only affect new sessions.
  7. What is Flue and how does it differ from built-in runtimes?

    main

    Flue is a TypeScript framework for building durable agents. Unlike OpenComputer's built-in runtimes (which manage agents like Claude Code or Codex), a Flue agent is a custom application where your application is the runtime.

    Key differences include:

    • Agent Loop: In Flue, your compiled application contains the agent loop.
    • Compute: Flue uses a single deployed app with one Durable Object instance per session, rather than managed per-session sandboxes.
    • State: Flue stores conversation state in Durable Object SQLite, while OpenComputer projects public milestones into its event log.
    • Tools: Tools are defined via defineTool code and packaged skill imports compiled into the Worker.
    • Deployment: You build and deploy a compiled application rather than just uploading prompts and skills.

    Under the hood, OpenComputer runs the Flue Cloudflare target as an agent Worker. This allows sessions to start without provisioning a virtual machine, using an ocSandbox only when specific operations require a Linux workspace.

  8. What is Reserved Capacity?

    main

    Reserved capacity allows you to pre-commit to memory usage for specific future 15-minute intervals at a significantly discounted rate compared to on-demand usage.

    Key Characteristics

    • Cost Savings: Reserved capacity is billed at $0.012/GB-hour, whereas on-demand (overage) is billed at $0.060/GB-hour.
    • Guaranteed Availability: Unlike on-demand capacity, which is subject to platform headroom, reserved capacity is guaranteed for the intervals you have booked.
    • Non-refundable: Once a commitment is made for an interval, it cannot be cancelled, transferred, or partially refunded. You should book conservatively.
    • Automatic Allocation: When running sandboxes during a reserved interval, they are automatically allocated against your reserved capacity. Any usage exceeding your reservation falls back to on-demand rates.
  9. What is a Sandbox?

    main
    A Sandbox is a compute primitive provided by OpenComputer: a full Linux virtual machine in the cloud. Each sandbox is isolated via hardware-level virtualization and possesses its own filesystem, network stack, and process space. They are designed to be disposable, starting in milliseconds and automatically hibernating or stopping when idle.
  10. Understand TTI benchmark modes

    main

    The benchmark supports three execution modes to simulate different load patterns:

    • sequential: Executes one sandbox at a time (concurrency 1). This is used to measure isolated cold-start performance.
    • staggered: Ramps up load with a 200ms delay between starts (concurrency 100).
    • burst: Executes all sandboxes at once (concurrency 100) to measure peak-demand performance.
  11. How sandbox templates and workflows work

    main

    OpenComputer provides two primary workflows for defining sandbox environments programmatically using the Image builder:

    1. Declarative images: You define an Image and pass it directly to Sandbox.create(image=...). The system builds the image on-the-fly during the first run and caches it by content hash. Subsequent sandboxes with the same image manifest will reuse the cached version instantly.
    2. Pre-built snapshots: You create a named, persistent snapshot using the Snapshots API. This is ideal for heavy environments (e.g., data science stacks) that you want to share across multiple sandboxes without rebuilding. Sandboxes created from snapshots boot instantly without a build step.

    Use Declarative images for rapid iteration and Snapshots for stable, reusable, and production-ready environments.

    # Pattern 1: On-demand image
    image = Image.base().apt_install(["curl"])
    sandbox = await Sandbox.create(image=image)
    
    # Pattern 2: Pre-built snapshot
    snapshots = Snapshots()
    await snapshots.create(name="my-snap", image=image)
    sandbox = await Sandbox.create(snapshot="my-snap")
  12. Understand the Sandbox and Runtime Tool Surface

    main

    When writing prompts for built-in runtimes (claude or codex), it is important to understand that the agent operates within a sandbox. The agent has no direct access to your local filesystem, shell, or network. Instead, it interacts with the sandbox through a fixed set of tools.

    Key Sandbox Constraints

    • Filesystem/Shell: All commands must be executed via the bash tool. Each call to bash is a fresh shell session, so you must use absolute paths or cd /workspace && ... to maintain state.
    • Network: The sandbox has open outbound internet by default (allowing git clone, package installs, etc.), but access to private, loopback, link-local, and cloud-metadata addresses is blocked.
    • Execution Events: A bash command execution surfaces as an exec.completed event containing the command, exit_code, and a summary. Large outputs are provided via a content_ref.