When to Use Containers
Use Containers when:- ✅ Need to customize agent code logic (
xpander_handler.py) - ✅ Integrate MCP servers that run locally (not in cloud)
- ✅ Need custom system dependencies (apt packages, libraries)
- ✅ Require specific base images or Python versions
- ✅ Want full control over runtime environment
- ✅ Need custom tools, models, or integrations
- ❌ Building agents with Workbench UI
- ❌ Don’t need custom code logic
- ❌ Standard connectors are sufficient
- ❌ Don’t want to manage code or Docker builds
Real-World Example: MCP Integration
Here’s an example of a containerized agent that integrates Alpha Vantage MCP for financial market analysis:xpander_handler.py
- Custom MCP Integration: Connects to Alpha Vantage MCP server with custom authentication
- Custom Model Configuration: Uses OpenAI GPT-5.2 with specific reasoning effort settings
- Custom Error Handling: Implements specialized logging and error management
- Environment-Specific Logic: Requires
ALPHAVANTAGE_API_KEYfrom environment
Quick Start
1
Install xpander CLI
2
Create New Agent Project
xpander_handler.py- Agent coderequirements.txt- Python dependenciesDockerfile- Container definition.env- Environment variablesagent.yaml- Agent configuration
3
Setup Virtual Environment
4
Test Locally
5
Test Container Locally
6
Deploy Container
7
View Logs
8
Invoke Agent
Project Structure
After runningxpander agent new, your project contains:
xpander_handler.py
xpander_handler.py
Dockerfile
Dockerfile
requirements.txt
requirements.txt
Customizing Your Container
Add System Dependencies
EditDockerfile to install OS-level packages:
Use Different Base Image
Add Private Dependencies
Local Development Workflow
1. Develop Without Container
2. Test Container Locally
3. Deploy to Production
- Builds your Docker image
- Pushes to container registry
- Deploys to xpander platform
- Makes agent available via API/SDK/Slack/webhooks
Environment Variables
Store sensitive configuration in.env file:
.env
- Used during local development (
xpander dev) - Loaded into container during local testing (
docker run --env-file .env) - Securely injected during production deployment (
xpander deploy)
Invoking Containerized Agents
Once deployed, invoke your containerized agent the same way as serverless agents:- CLI
- SDK
- REST API
CLI Commands Reference
Container vs Serverless
Troubleshooting
Build Fails
Container Runs Locally But Fails in Production
- Verify environment variables are set correctly
- Check logs:
xpander logs - Ensure base image architecture matches deployment target
- Validate network access to external APIs
Large Image Size
Related
Agent Serverless
Default deployment mode without containers
Self-Hosted Deployment
Run on your own infrastructure
CLI Reference
Complete CLI command reference

