-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat: Add sandbox isolation for background agents #8238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brosand
wants to merge
19
commits into
anomalyco:dev
Choose a base branch
from
brosand:sandbox-isolation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,090
−154
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
src/sandbox/provider.ts) - DefinesSandbox.Providerinterface with registration systemsrc/sandbox/local.ts) - Git worktree-based isolation (existing behavior, refactored)src/sandbox/modal.ts) - Modal.com cloud VM integrationsrc/sandbox/kubernetes.ts) - K8s pod-based sandboxesRuntime Layer
src/sandbox/runtime.ts) - Auto-routing layer that detects remote vs local executionsrc/sandbox/context.ts) - Session-to-sandbox lifecycle bindingsrc/sandbox/fs.ts) - Unified file operations interfaceTool Integrations
Updated all file/exec tools to use SandboxRuntime:
read.ts,write.ts,edit.ts,patch.tsglob.ts,grep.ts,ls.tsbash.ts,lsp.tsAPI
GET /session/:sessionID/sandboxendpoint for sandbox statusSessionSandboxStatustype to SDKConfiguration
{ "sandbox": { "provider": "modal", // or "kubernetes" or "local" "modal": { "image": "python:3.11" }, "kubernetes": { "namespace": "default", "image": "ubuntu:22.04" } } }Testing
Documentation