Self-Host OpenClaw AI Agent on Raspberry Pi with Docker
Learn to self-host OpenClaw AI agent on Raspberry Pi with Docker, Traefik routing, cost monitoring via Clawmetry, and Telegram-based human approval workflo
Originally published:
A comprehensive guide demonstrates how developers can self-host OpenClaw, an autonomous AI agent gateway, on a Raspberry Pi using Docker containers for 24/7 operation. The setup provides cost-controlled access to large language models through everyday messaging platforms while maintaining data sovereignty and system security.
OpenClaw functions as a gateway connecting powerful LLMs like Claude 3.5 Sonnet and GPT-4o to messaging platforms including WhatsApp, Telegram, and Discord. Unlike traditional chatbots, the system grants agents access to tools for web searches, calendar management, and code execution on local networks. This capability introduces significant security considerations that simple script-based installations fail to address.
Docker-Based Architecture for Security
The recommended production setup isolates the AI agent in Docker containers rather than running directly on the host system. This containerization prevents potentially dangerous autonomous actions from compromising the entire Raspberry Pi. A Traefik reverse proxy handles routing, enabling access via clean URLs like openclaw.local instead of IP addresses and ports.
The architecture includes four core services: Traefik for reverse proxy functionality on port 80, the OpenClaw gateway container exposing the web interface on port 18789, a CLI container for administrative tasks including channel authentication, and a socat proxy enabling internal gateway communication. The configuration mounts persistent volumes at ~/.openclaw for data retention across container restarts.
Human-in-the-Loop Control via Telegram
The system implements approval workflows through messaging platforms. When OpenClaw attempts critical operations like file deletion or script execution, it sends push notifications with "Approve" or "Deny" buttons. This pattern enables remote task delegation while maintaining human oversight over potentially destructive actions.
Initial channel authentication requires running the CLI container: docker compose run --rm openclaw-cli channels login telegram. Once configured, users can send natural language requests like "Research today's top 5 AI news and save a summary PDF to Dropbox" and receive real-time status updates with approval prompts for sensitive operations.
Cost Monitoring with Clawmetry
Autonomous agents running continuously can generate unexpected API costs through repeated retry loops, documentation reading, and self-correction cycles. Without monitoring, overnight operation can accumulate $50+ in LLM API charges from providers like Anthropic and OpenAI.
The guide integrates Clawmetry-Docker, a specialized monitoring dashboard accessible at stats.openclaw.local, which visualizes token consumption by agent, real-time cost analysis in local currency, and response latency metrics. The dashboard runs as a sidecar container sharing the OpenClaw configuration directory, providing transparency into which operations consume the most budget.
Security Hardening Requirements
Default OpenClaw and Clawmetry installations expose web interfaces without authentication, creating significant security risks. Anyone on the local network could control agents or generate unbounded API costs. The guide emphasizes three critical protections:
- Implement Traefik middleware for HTTP basic authentication on all web interfaces
- Never expose ports 18789 or 8900 directly through router port forwarding
- Use VPN solutions like WireGuard or Tailscale for remote access instead of public internet exposure
The Docker Compose configuration uses stdin_open and tty flags to maintain interactive terminal sessions within containers, essential for CLI operations. Environment variables ANTHROPIC_API_KEY and OPENAI_API_KEY should be populated from secure secret management rather than hardcoded in configuration files.
Key Takeaways
- OpenClaw transforms Raspberry Pi into a 24/7 AI agent gateway connecting LLMs to messaging platforms with tool access
- Docker isolation prevents autonomous agent errors from compromising the host system
- Traefik reverse proxy enables clean URL routing and simplifies future HTTPS certificate integration
- Human-in-the-loop approval workflows via Telegram maintain control over critical operations
- Real-time cost monitoring prevents unexpected LLM API bills from continuous autonomous operation
- Proper authentication and VPN access are essential security requirements before deployment
Based on the detailed guide by Stephan Strittmatter, published on Medium, with full Docker Compose configurations available in the clawmetry-docker repository.
Original Source
https://stritti.medium.com/jenseits-von-chatgpt-wie-du-mit-openclaw-und-einem-raspberry-pi-deinen-eigenen-autonomen-aba822c1f92c?source=rss------openclaw-5
Last updated: