Skip to main content

What are Environments?

Environments provide isolated execution contexts for general AI agents, allowing them to safely run code, access files, and execute shell commands. The PandaAGI SDK offers three main environment types that balance security, performance, and ease of use.

Local Environment

Direct execution on the host system with working directory isolation

Docker Environment

Containerized execution with strong isolation and port management

File Operations

Read, write, delete files with support for various formats including PDFs

Shell Execution

Execute shell commands with both blocking and non-blocking modes

E2B Environment

Cloud-based sandbox execution with secure isolation via E2B SDK

Local Environment

The LocalEnv executes operations directly on the host filesystem within a specified base directory:

Docker Environment

The DockerEnv runs operations inside a Docker container for better isolation:

Basic Setup

Volume Mounting

Mount additional directories from the host:

Environment Variables

Pass environment variables to the container:

Port Management

The Docker environment automatically exposes port 2664 (PandaAGI default) and allows custom port mappings:

Network Configuration

Connect to existing Docker networks:

File Operations

All environments support comprehensive file operations:

Writing Files

Reading Files

File Management

Shell Command Execution

Blocking Execution

Non-blocking Execution

Perfect for long-running processes or interactive commands:

E2B Environment

The E2BEnv executes operations in a secure cloud-based sandbox using the E2B Code Interpreter SDK, providing strong isolation without requiring Docker:

Key Features

  • Cloud-based Execution: All operations run in a secure, isolated cloud environment
  • No Local Installation: No need to install Docker or other dependencies locally
  • Automatic Cleanup: Sandbox resources are automatically cleaned up after use
  • Consistent Interface: Uses the same API as other environment types for seamless switching

Container Lifecycle Management

For Docker environments, you can control the container lifecycle:

Best Practices

Choose the right environment for your use case:
Always check operation results: python result = await env.exec_shell("command") if result["status"] != "success": logger.error(f"Command failed: {result.get("message", result.get("stderr"))}") return # Process successful result print(result["stdout"])
Use relative paths within the environment:

Troubleshooting

Common Docker-related problems:
Handle port binding conflicts:
Handle process lifecycle issues:

Next Steps

Quickstart

Get started quickly with PandaAGI

API Key

Learn how to obtain and use your API key