Skip to content

Conversation

@brosand
Copy link

@brosand brosand commented Jan 13, 2026

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

- Add Sandbox namespace with Provider and Instance interfaces
- Define schemas: Config, ExecResult, Info, Snapshot, FileInfo
- Add error types: CreateError, NotFoundError, ExecError, etc.
- Implement LocalSandboxProvider wrapping existing worktree functionality
- Provider registry for registering/retrieving sandbox providers
- Add ModalSandboxProvider for cloud-based sandboxes
- Add sandbox configuration to Config schema
- Export providers from sandbox index
- Add SandboxContext for managing sandbox lifecycle per session
- Add SandboxFS for routing file/exec operations through sandbox
- Support automatic sandbox creation/cleanup for sessions
- Provide isRemote() helper to detect cloud sandbox mode
…tion

- Add KubernetesSandboxProvider for running sandboxes in K8s pods
- Add comprehensive unit tests for LocalSandboxProvider, SandboxRuntime, and provider types (65 tests)
- Add Session.SandboxStatus schema and getSandboxStatus() function
- Add GET /session/:sessionID/sandbox API endpoint
- Add JSDoc documentation to public APIs in provider.ts and runtime.ts
- Add README.md documenting sandbox module architecture and usage
- Fix Hono type inference issue with ts-expect-error comment
- Add try/catch with proper error types in SandboxContext.getOrCreateForSession
- Wrap sandbox file operations with Sandbox.FileError in runtime.ts
- Wrap sandbox exec operations with Sandbox.ExecError in runtime.ts
- Add graceful handling for sandbox termination failures
- Make isRemote() safe when called outside context
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant