Skip to main content
The docker sandboxed agent server demonstrates how to run agents in isolated Docker containers using DockerWorkspace. This provides complete isolation from the host system, making it ideal for production deployments, testing, and executing untrusted code safely.
the Docker sandbox image ships with features configured in the Dockerfile (e.g., secure defaults and services like VSCode and VNC exposed behind well-defined ports), which are not available in the local (non-Docker) agent server.

1) Basic Docker Sandbox

This example shows how to create a DockerWorkspace that automatically manages Docker containers for agent execution:
examples/02_remote_agent_server/02_convo_with_docker_sandboxed_server.py
Running the Example

Key Concepts

DockerWorkspace Context Manager

The DockerWorkspace uses a context manager to automatically handle container lifecycle:
The workspace automatically:
  • Pulls or builds the Docker image
  • Starts the container with an agent server
  • Waits for the server to be ready
  • Cleans up the container when done

Platform Detection

The example includes platform detection to ensure the correct Docker image is built and used:
This ensures compatibility across different CPU architectures (Intel/AMD vs ARM/Apple Silicon).

Testing the Workspace

Before creating a conversation, the example tests the workspace connection:
This verifies the workspace is properly initialized and can execute commands.

Automatic RemoteConversation

When you use a DockerWorkspace, the Conversation automatically becomes a RemoteConversation:
The SDK detects the remote workspace and uses WebSocket communication for real-time event streaming.

Pre-built vs Base Images

Pre-built images start immediately, while base images need to build the agent server first.

2) VS Code in Docker Sandbox

VS Code with Docker demonstrates how to enable VS Code Web integration in a Docker-sandboxed environment. This allows you to access a full VS Code editor running in the container, making it easy to inspect, edit, and manage files that the agent is working with.
examples/02_remote_agent_server/04_vscode_with_docker_sandboxed_server.py
Running the Example

Key Concepts

VS Code-Enabled DockerWorkspace

The workspace is configured with extra ports for VS Code access:
The extra_ports=True setting exposes:
  • Port host_port+1: VS Code Web interface (host_port + 1)
  • Port host_port+2: VNC viewer for visual access

VS Code URL Generation

The example retrieves the VS Code URL with authentication token:
This generates a properly authenticated URL with the workspace directory pre-opened.

VS Code URL Format

  • vscode_port: Usually host_port + 1 (e.g., 8011)
  • tkn: Authentication token for security
  • folder: Workspace directory to open

3) Browser in Docker Sandbox

Browser with Docker demonstrates how to enable browser automation capabilities in a Docker-sandboxed environment. This allows agents to browse websites, interact with web content, and perform web automation tasks while maintaining complete isolation from your host system. This example shows how to configure DockerWorkspace with browser capabilities and VNC access:
examples/02_remote_agent_server/03_browser_use_with_docker_sandboxed_server.py
Running the Example

Key Concepts

Browser-Enabled DockerWorkspace

The workspace is configured with extra ports for browser access:
The extra_ports=True setting exposes additional ports for:
  • Port host_port+1: VS Code Web interface
  • Port host_port+2: VNC viewer for browser visualization

Enabling Browser Tools

Browser tools are enabled by setting cli_mode=False:
When cli_mode=False, the agent gains access to browser automation tools for web interaction. When VNC is available and extra_ports=True, the browser will be opened in the VNC desktop to visualize agent’s work. You can watch the browser in real-time via VNC. Demo video:

VNC Access

The VNC interface provides real-time visual access to the browser:
  • autoconnect=1: Automatically connect to VNC server
  • resize=remote: Automatically adjust resolution

Next Steps