Overview
Agent Sandbox provides a unified API for isolated command execution across multiple backends. Whether you need local process isolation, Docker container security, or cloud-based E2B microVMs, the same interface works everywhere. The library emphasizes clean design: interface segregation (separate concerns for execution vs file operations), Liskov substitution (backends are interchangeable), and a JDK 21 baseline for modern Java features.Core API
Sandbox
Main interface for isolated command execution with workspace management
ExecSpec
Command specification with timeout, environment, and shell support
ExecResult
Execution result with exit code, stdout, stderr, and utilities
SandboxFiles
Fluent API for file operations within the sandbox workspace
Module Structure
| Module | Description | Dependencies |
|---|---|---|
agent-sandbox-core | Core Sandbox API and LocalSandbox | zt-exec |
agent-sandbox-docker | Docker container sandbox | testcontainers |
agent-sandbox-e2b | E2B cloud microVM sandbox | jackson, awaitility |
agent-sandbox-bom | Bill of Materials | N/A |
Implementations
LocalSandbox
Local process execution using zt-exec. Fast, no isolation overhead.
DockerSandbox
Container-based isolation using Testcontainers. Full filesystem/network isolation.
E2BSandbox
Cloud microVM execution via E2B. Maximum isolation with MCP support.
Quick Start
Maven Dependency
Basic Execution
Sandbox Interface
ExecSpec (Command Specification)
Build command specifications with fluent API:ExecResult (Execution Result)
Rich result object with utilities for AI analysis:SandboxFiles (File Operations)
Fluent API for file management with.and() to chain back to sandbox:
Batch File Setup
FileEntry (File Metadata)
ExecSpecCustomizer
Inject cross-cutting concerns (auth, logging, etc.) before every execution:LocalSandbox
Fast local execution without container overhead:Interactive Processes
For bidirectional I/O (stdin/stdout streaming):DockerSandbox
Container isolation for untrusted code:ghcr.io/spring-ai-community/agents-runtime:latest
Working directory: /work
E2BSandbox
Cloud-based Firecracker microVM for maximum isolation:/home/user
Session Reconnection
Reconnect to existing E2B sandbox for persistent sessions:E2B sandboxes support MCP (Model Context Protocol) for AI agent integration. See the E2B documentation for details.
Exceptions
Design Principles
Interface Segregation
Interface Segregation
The
Sandbox interface focuses on command execution, while SandboxFiles handles file operations. This separation allows implementations to optimize each concern independently.Liskov Substitution
Liskov Substitution
All sandbox implementations are interchangeable. Code written for
LocalSandbox works identically with DockerSandbox or E2BSandbox:JDK 21 Baseline
JDK 21 Baseline
Built for modern Java with:
- Virtual threads for concurrent operations
- Pattern matching and sealed classes
- Modern NIO file APIs
- Try-with-resources for automatic cleanup
Used By
Agent Sandbox is used by:- Agent Judge - The
agent-judge-execmodule uses sandboxes for command-based evaluation - Agent Client - Provides isolated execution environments for autonomous agents