Skip to main content
The sandbox provides an isolated execution environment where agents can read files, write files, and execute commands safely.

Overview

DeerFlow’s sandbox system supports multiple execution modes:

Local

Direct execution on the host filesystem

Docker

Isolated containers with AIO Sandbox

Kubernetes

Provisioner-managed pods at scale

Sandbox Interface

All sandbox providers implement the abstract Sandbox interface:

Virtual Path System

The sandbox uses virtual paths to isolate threads: Agent View (Virtual):
Physical Paths:

Path Translation

The sandbox translates between virtual and physical paths:
Path translation is transparent to the agent. Use virtual paths in prompts and tools.

Local Sandbox

The local sandbox executes directly on the host machine. Configuration (config.yaml):
Features:
  • Fast execution (no container overhead)
  • Direct filesystem access
  • Simple debugging
Use Cases:
  • Local development
  • Trusted environments
  • CI/CD pipelines
Local sandbox has no isolation. Use only in trusted environments.

Docker Sandbox (AIO)

The Docker sandbox runs commands in isolated containers via the AIO Sandbox library. Configuration (config.yaml):
Features:
  • Process isolation
  • Resource limits (CPU, memory)
  • Network isolation
  • Automatic cleanup
Volume Mounts:
  • Thread data: {host_thread_path} → /mnt/user-data
  • Skills: {host_skills_path} → /mnt/skills

Docker Setup Guide

Configure Docker sandbox for development

Kubernetes Sandbox (Provisioner)

For production deployments, the Kubernetes sandbox creates pods on-demand via a provisioner service. Configuration (config.yaml):
Architecture:
Features:
  • Horizontal scaling
  • Resource quotas
  • Pod security policies
  • Persistent storage

Kubernetes Deployment

Deploy DeerFlow with Kubernetes sandboxes

Sandbox Lifecycle

Sandboxes are managed by the SandboxMiddleware:
Lifecycle:
  1. Acquire: Get or create sandbox for thread
  2. Execute: Run commands and file operations
  3. Release: Return sandbox to pool or destroy

Sandbox Tools

The sandbox provides five core tools:
Execute shell commands in the sandbox.
Path Translation: Automatic for virtual pathsError Handling: Returns stderr and exit code
List directory contents in tree format.
Output: Tree format, max 2 levels deep
Read file contents with optional line range.
Write or append to files.
Auto-creates: Parent directories as needed
Replace text in files (single or all occurrences).

Sandbox Tools API

View complete tool reference

Thread Isolation

Each thread has its own isolated filesystem:
Benefits:
  • No cross-contamination between threads
  • Concurrent execution without conflicts
  • Easy cleanup (delete thread directory)

Platform Differences

Sandbox behavior varies by platform:
  • Docker socket: /var/run/docker.sock
  • Native path mounting
  • Best performance

Best Practices

Always reference /mnt/user-data/ and /mnt/skills/ in prompts:
Not: backend/.deer-flow/threads/abc123/user-data/uploads/data.csv
User-facing files should go in the outputs directory:
Then present with present_files(["/mnt/user-data/outputs/report.html"])
Remove temporary files in workspace after use:
Check command exit codes:

Next Steps

Sandbox Configuration

Configure sandbox providers

Sandbox Tools

Tool API reference

Docker Setup

Set up Docker sandbox

Kubernetes

Deploy with K8s sandboxes