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
TheLocalEnv executes operations directly on the host filesystem within a specified base directory:
Docker Environment
TheDockerEnv 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
TheE2BEnv 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
Environment Selection
Environment Selection
Choose the right environment for your use case:
Error Handling
Error Handling
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"]) Path Management
Path Management
Use relative paths within the environment:
Troubleshooting
Docker Container Issues
Docker Container Issues
Common Docker-related problems:
Port Conflicts
Port Conflicts
Handle port binding conflicts:
Process Management
Process Management
Handle process lifecycle issues: