Skip to main content
This project has moved to markpollack/agent-sandbox. Current documentation is at lab.pollack.ai/projects/agent-sandbox. The content below may be outdated.
Incubating Status GitHubMaven Central

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

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:
Default image: ghcr.io/spring-ai-community/agents-runtime:latest Working directory: /work

E2BSandbox

Cloud-based Firecracker microVM for maximum isolation:
Working directory: /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

The Sandbox interface focuses on command execution, while SandboxFiles handles file operations. This separation allows implementations to optimize each concern independently.
All sandbox implementations are interchangeable. Code written for LocalSandbox works identically with DockerSandbox or E2BSandbox:
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-exec module uses sandboxes for command-based evaluation
  • Agent Client - Provides isolated execution environments for autonomous agents

Resources

GitHub Repository

Source code and contribution guidelines

E2B Documentation

E2B cloud sandbox platform

License

Agent Sandbox is Open Source software released under the Apache 2.0 license.