Routing AI Agents: How to Pass Network Proxy Env to OpenClaw Docker Containers

When deploying OpenClaw in containerized enterprise networks or local sandboxes behind strict firewalls, network proxy configuration is the single most common point of failure. AI agents rely heavily on outbound connection pipelines—whether calling external LLM providers (like OpenAI, Anthropic, or DeepSeek), cloning repositories from GitHub, running package updates, or scraping web sources.
If these containers are launched without explicit proxy propagation, your agent runs will immediately stall with socket timeouts, connection refused errors, or pip installation failures. Merely setting proxy variables on the host operating system is insufficient; Docker containers run in isolated network namespaces and do not inherit host shell profiles.
This guide provides the authoritative, production-grade manual for routing your OpenClaw Docker container through local or corporate HTTP, HTTPS, and SOCKS5 proxies, ensuring stable routing across host loopbacks, Python virtual environments, and CLI tools.
Summary
| Question | Direct answer |
|---|---|
| Why doesn't host proxy setting automatically apply to OpenClaw Docker containers? | Docker containers run in isolated networking namespaces. By default, they do not inherit environment variables or host files (like `/etc/resolv.conf` or proxy profiles) from the host shell. |
| What is the standard way to pass proxy environment variables to Docker? | Pass runtime environment variables (`HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`) using the `-e` flag in `docker run` or under the `environment:` section in a `docker-compose.yml` file. |
| How do you resolve "localhost" proxy routing issues from inside a container? | Use `host.docker.internal` instead of `127.0.0.1` or `localhost`, and include the `--add-host=host.docker.internal:host-gateway` flag on Linux platforms to enable host-loopback routing. |
| How can you solve SSL certificate verification errors for enterprise proxies? | Inject custom root certificates into the container's CA store, or configure the Python runtime with `REQUESTS_CA_BUNDLE` and `CURL_CA_BUNDLE` pointing to your enterprise certificate authority chain. |
Definition: Network proxy env propagation is the system practice of explicitly passing, formatting, and locking HTTP, HTTPS, and SOCKS5 gateway environment variables into a Docker container's environment space, ensuring that both system-level tools (such as `curl`, `wget`, `apt`) and application-level processes (such as Python `requests`, `urllib3`, Node.js runtimes) route their outbound sockets through an intermediary server.
Quotable takeaway: Isolated networks require deliberate configurations. Passing proxy variables to a container is only half the battle; ensuring that downstream Python virtual environments and runner sub-processes respect those variables—without tripping over local hostname mappings—is what separates a broken agent from a highly resilient enterprise deployment.
Understanding Container Network Isolation and Proxy Bridges
To successfully configure proxy environments, one must understand how network requests exit a Docker container.
By default, Docker establishes a virtual bridge network (usually `172.17.0.0/16`), assigning the host system as the default gateway (`172.17.0.1`). When a containerized application requests an external API, the request is routed from the container's virtual network interface (`eth0`) through the bridge to the host, which then routes it to the physical network card.
If your host workstation is behind a corporate proxy, any outbound request from the container that does not specify a proxy IP will attempt a direct connection to the internet, which the corporate firewall will instantly block.
---
The Complete CLI and docker-compose.yml Proxy Configurations
To route all containerized network requests through your proxy server, you must pass the appropriate environment variables. These must be declared in both uppercase and lowercase because different developer tools check different variables (for example, `curl` prefers lowercase `http_proxy`, while Python's `urllib` checks uppercase `HTTP_PROXY`).
1. The Single-Container CLI Method (Command Line)
To launch a single OpenClaw gateway container with proxy routing, use the `-e` environment flags:
```bash docker run -d \ --name openclaw-gateway \ -p 18789:18789 \ -e HTTP_PROXY="http://10.0.0.15:7890" \ -e HTTPS_PROXY="http://10.0.0.15:7890" \ -e NO_PROXY="localhost,127.0.0.1,host.docker.internal,openclaw-redis" \ -v /Users/hutao/.openclaw/workspace:/app/workspace \ openclaw/gateway:latest ```
2. The Docker Compose Multi-Container Method
For modern multi-container setups, define your proxy environment variables inside your `docker-compose.yml` file under the respective services. Note how we can reference the variables dynamically from a host-level `.env` file to keep configurations clean:
```yaml version: '3.8'
services: openclaw-gateway: image: openclaw/gateway:latest container_name: openclaw-gateway ports:
volumes:
environment:
depends_on:
restart: unless-stopped
- "18789:18789"
- ./workspace:/app/workspace
- HTTP_PROXY=${HOST_PROXY}
- HTTPS_PROXY=${HOST_PROXY}
- http_proxy=${HOST_PROXY}
- https_proxy=${HOST_PROXY}
- NO_PROXY=localhost,127.0.0.1,host.docker.internal,redis-vector
- no_proxy=localhost,127.0.0.1,host.docker.internal,redis-vector
- redis-vector
redis-vector: image: redis:7-alpine container_name: redis-vector restart: unless-stopped ```
Create a matching `.env` file in the same folder to specify your proxy server: ```properties HOST_PROXY=http://host.docker.internal:7890 ```
---
Solving the Local Loopback ("localhost") Routing Trap
If your proxy is running on your host machine (e.g. a local proxy app like Clash, v2ray, or a corporate VPN tunnel on `127.0.0.1:7890`), writing `HTTP_PROXY="http://127.0.0.1:7890"` inside the container will fail. The container will attempt to route the request inside its own loopback interface, where no proxy is listening.
Resolving the Host Loopback on Windows & macOS
Use the special DNS name `host.docker.internal` which Docker automatically resolves to your physical host machine's gateway IP address: ```yaml environment:
```
- HTTP_PROXY=http://host.docker.internal:7890
- HTTPS_PROXY=http://host.docker.internal:7890
Resolving the Host Loopback on Linux
Natively, Docker on Linux does not resolve `host.docker.internal` automatically. You must explicitly inject the host-gateway routing map inside your CLI command or compose file:
CLI command flag: `--add-host=host.docker.internal:host-gateway` Docker Compose mapping: ```yaml extra_hosts:
```
- "host.docker.internal:host-gateway"
---
Injecting Corporate SSL Certificates (Deep Packet Inspection)
Many enterprise proxies perform SSL Decryption and Inspection, intercepting encrypted traffic and re-signing packets using a custom enterprise Certificate Authority (CA) root certificate. If your container lacks this custom root certificate, any HTTPS request (such as calling OpenAI) will crash with a major security exception: ``` self-signed certificate in certificate chain ```
To resolve this securely, you must mount and trust your enterprise CA root certificate inside your OpenClaw container.
Step-by-Step CA Certificate Injection:
- Copy your corporate root certificate file (e.g. `corp_ca.crt`) to your local OpenClaw folder.
- Mount the certificate file directly into the container's trusted CA folder and set the environment variables to instruct Node.js and Python to trust it:
```yaml
services:
openclaw-gateway:
image: openclaw/gateway:latest
volumes:
environment:
```
- ./workspace:/app/workspace
- ./corp_ca.crt:/usr/local/share/ca-certificates/corp_ca.crt:ro
- NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/corp_ca.crt
- REQUESTS_CA_BUNDLE=/usr/local/share/ca-certificates/corp_ca.crt
- CURL_CA_BUNDLE=/usr/local/share/ca-certificates/corp_ca.crt
---
Troubleshooting Common Container Proxy Failures
When configuring proxies, check for these common syntax errors and apply the fixes immediately.
Error 1: Local Ollama or Vector Databases Timeout
You have configured your proxy variables correctly, and your container can connect to OpenAI. But when OpenClaw attempts to search a local vector database container or connect to local Ollama, the request hangs or fails. The Cause: The proxy variables are globally intercepting ALL container traffic, attempting to route local internal container connections through your external proxy, which cannot find them. The Solution: Add the local container service names and loopbacks to your `NO_PROXY` and `no_proxy` environment variables (e.g., `NO_PROXY="localhost,127.0.0.1,host.docker.internal,redis-vector,ollama"`).
Error 2: Single Casing Variable Exclusions
Some tools in your runner work perfectly, while others fail with network timeouts. The Cause: You defined `HTTP_PROXY` in uppercase, but some container utilities (like `wget` or `apt-get`) only check the lowercase `http_proxy` variable. The Solution: Ensure that you define both cases inside your container environment configuration: `HTTP_PROXY` and `http_proxy` `HTTPS_PROXY` and `https_proxy` * `NO_PROXY` and `no_proxy`
---
Bypassing Docker Proxy Configuration Entirely with ClawLite
While passing proxy environments into Docker containers is a critical skill for advanced DevOps engineers, managing container-network isolation namespaces, host loopbacks (`host.docker.internal`), and SSL certificate injections can be highly complex and error-prone.
If you are looking for a zero-configuration local-first solution that automatically inherits your system's global network and proxy setup without any manual environment-variable passing, the ClawLite Desktop App is the ideal solution.
ClawLite runs natively on your development workstation inside your user execution space, bypassing containerization layers completely.
Native System Proxy Inheritance: ClawLite automatically detects and inherits your operating system's global proxy settings (including HTTP, HTTPS, SOCKS5, and PAC configurations) right out of the box. No manual `HTTP_PROXY` environment variable passing or casing duplication required. Direct Localhost Connections: Because ClawLite runs natively on your host machine, it connects instantly to other local services (such as Ollama on `127.0.0.1:11434` or local vector databases) with zero network bridge routing, DNS resolving, or `host.docker.internal` hacks. Seamless SSL Verification*: Since ClawLite utilizes your workstation's native CA certificate store, any corporate root certificates already installed on your machine are automatically trusted, completely eliminating Python `requests` and `curl` SSL validation errors.
For developers and teams who want a visual, high-performance, and secure agent runtime that connects to enterprise networks instantly with zero networking overhead, ClawLite is the ultimate choice.
---
FAQ
Does OpenClaw's Node.js engine require a separate proxy package?
No. OpenClaw uses standard network agent controllers that automatically read and bind to global system variables (`HTTP_PROXY` and `HTTPS_PROXY`). It transparently formats connection requests and passes proxy configurations to child runners automatically.
What should I put in NO_PROXY to prevent routing failures?
Your `NO_PROXY` string is highly critical. It must include any server that OpenClaw connects to locally on your machine or network. If you run a local vector database (like ChromaDB, Qdrant, or Milvus) or a local LLM runner (like Ollama or LocalAI) in other containers, add their container names or host gateway IPs (e.g., `ollama-container,qdrant-container,127.0.0.1,localhost`) to `NO_PROXY` to prevent the agent from attempting to route local traffic through your external proxy, which would result in routing loops or packet dropouts.
Can I configure proxy environments dynamically without restarting the container?
No. Environment variables are set during process initialization. To change proxy addresses or protocols, you must recreate or update your container via `docker run` or `docker compose up -d`.
How do I handle password-protected proxies?
If your corporate gateway requires user authentication, inject credentials directly into the URL schema: `HTTP_PROXY="http://username:[email protected]:8080"` Ensure any special characters in your password (like `@`, `:`, `/`) are properly URL-encoded (e.g., `@` becomes `%40`).
Is it possible to use different proxies for different agent tasks?
Yes. While the Docker environment variables establish the container-wide default gateway, individual agent scripts or customized workspaces can overwrite standard python environment states programmatically by declaring `os.environ["HTTP_PROXY"] = "..."` within their runtime execution hooks.
Methodology and Sources
The proxy configuration configurations, networking topologies, and error validations documented in this deployment guide are compiled from these operational directories: Official Docker Network and Bridge Specification architecture catalogs. Empirical testing of SSL decryption injection pathways on enterprise Squid proxy nodes. * The ClawLite networking specifications for proxy gateways and runner container bridges.
For deeper insights into enterprise configurations or API network routing, explore the ClawLite docs, check out the ClawRouter overview, and read the ClawLite setup page.
Conclusion
Passing network proxy variables into your OpenClaw Docker containers is a critical prerequisite for building robust, enterprise-grade AI agent networks. By properly mapping local loopbacks, ensuring identical casing across both lowercase and uppercase environment declarations, and handling deep packet SSL inspections with custom root CA mount folders, you establish a resilient runtime environment.
This architecture ensures that your containerized agents execute with maximum speed and reliability, completely free from the network timeouts and dependency isolation loops that plague default virtualized containers.