[PR #8238] feat: Add sandbox isolation for background agents #12669

Open
opened 2026-02-16 18:17:34 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8238

State: open
Merged: No


Summary

This PR implements cloud sandbox-based isolation for background agents, enabling them to run in isolated environments (Modal VMs or Kubernetes pods) instead of git worktrees.

Changes

Core Infrastructure

  • Provider Abstraction (src/sandbox/provider.ts) - Defines Sandbox.Provider interface with registration system
  • Local Provider (src/sandbox/local.ts) - Git worktree-based isolation (existing behavior, refactored)
  • Modal Provider (src/sandbox/modal.ts) - Modal.com cloud VM integration
  • Kubernetes Provider (src/sandbox/kubernetes.ts) - K8s pod-based sandboxes

Runtime Layer

  • SandboxRuntime (src/sandbox/runtime.ts) - Auto-routing layer that detects remote vs local execution
  • Context Management (src/sandbox/context.ts) - Session-to-sandbox lifecycle binding
  • Filesystem Abstraction (src/sandbox/fs.ts) - Unified file operations interface

Tool Integrations

Updated all file/exec tools to use SandboxRuntime:

  • read.ts, write.ts, edit.ts, patch.ts
  • glob.ts, grep.ts, ls.ts
  • bash.ts, lsp.ts

API

  • Added GET /session/:sessionID/sandbox endpoint for sandbox status
  • Added SessionSandboxStatus type to SDK

Configuration

{
  "sandbox": {
    "provider": "modal",  // or "kubernetes" or "local"
    "modal": { "image": "python:3.11" },
    "kubernetes": { "namespace": "default", "image": "ubuntu:22.04" }
  }
}

Testing

  • 65 new unit tests for sandbox module
  • All 717 tests pass
  • Typecheck passes

Documentation

  • JSDoc for all public APIs
  • README with architecture diagram and usage examples
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8238 **State:** open **Merged:** No --- ## Summary This PR implements cloud sandbox-based isolation for background agents, enabling them to run in isolated environments (Modal VMs or Kubernetes pods) instead of git worktrees. ## Changes ### Core Infrastructure - **Provider Abstraction** (`src/sandbox/provider.ts`) - Defines `Sandbox.Provider` interface with registration system - **Local Provider** (`src/sandbox/local.ts`) - Git worktree-based isolation (existing behavior, refactored) - **Modal Provider** (`src/sandbox/modal.ts`) - Modal.com cloud VM integration - **Kubernetes Provider** (`src/sandbox/kubernetes.ts`) - K8s pod-based sandboxes ### Runtime Layer - **SandboxRuntime** (`src/sandbox/runtime.ts`) - Auto-routing layer that detects remote vs local execution - **Context Management** (`src/sandbox/context.ts`) - Session-to-sandbox lifecycle binding - **Filesystem Abstraction** (`src/sandbox/fs.ts`) - Unified file operations interface ### Tool Integrations Updated all file/exec tools to use SandboxRuntime: - `read.ts`, `write.ts`, `edit.ts`, `patch.ts` - `glob.ts`, `grep.ts`, `ls.ts` - `bash.ts`, `lsp.ts` ### API - Added `GET /session/:sessionID/sandbox` endpoint for sandbox status - Added `SessionSandboxStatus` type to SDK ### Configuration ```json { "sandbox": { "provider": "modal", // or "kubernetes" or "local" "modal": { "image": "python:3.11" }, "kubernetes": { "namespace": "default", "image": "ubuntu:22.04" } } } ``` ## Testing - 65 new unit tests for sandbox module - All 717 tests pass - Typecheck passes ## Documentation - JSDoc for all public APIs - README with architecture diagram and usage examples
yindo added the pull-request label 2026-02-16 18:17:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12669