Feb 10, 2026 · 8 min read · MCP / AI agent security / Docker
How to Secure OpenClaw with fastn UCL: Docker Isolation, MCP Gateway Integration, and Production-Grade AI Agent Security
A hands-on guide to running OpenClaw safely using Docker container isolation for the host and fastn UCL as a governed MCP gateway for tools and credentials.
By fastn team
OpenClaw is everywhere. With 180,000+ GitHub stars and native support for WhatsApp, Slack, Discord, Gmail, and more, it has become the most popular open-source AI agent framework in the world. Developers are using it to automate workflows, manage communications, and build autonomous digital assistants that operate across their entire app ecosystem.
But here is the challenge: giving an autonomous agent unrestricted access to your tools is a security risk. When OpenClaw can execute shell commands, control browsers, read your emails, and send messages on your behalf, the attack surface is large. Security researchers have already flagged credential leakage, privilege escalation, and supply chain vulnerabilities as real-world threats.
This guide walks through how to run OpenClaw securely using Docker container isolation and fastn UCL (Unified Context Layer) as your MCP gateway. We tested every step hands-on and documented the exact configuration that gets you from zero to a production-ready, governed AI agent deployment.
Why This Matters: MCP Alone Is Not Enough
Model Context Protocol (MCP) standardises how AI agents describe and execute commands across tools. It is a critical first step. But MCP only defines the structure, not the infrastructure.
A raw MCP server gives your agent tool access, but it leaves the hard problems unsolved. Where do OAuth tokens live? Who decides which actions the agent can take? What happens when an agent tries to delete all your emails instead of reading them? How do you audit what the agent actually did?
Without an orchestration and governance layer, you end up with credentials stored in plaintext config files, agents with unrestricted API access, and zero visibility into what is happening. That is a prototype, not a production deployment.
MCP gives us the language for agent actions. fastn UCL gives us the infrastructure to make them work in production.
Three Risks Every OpenClaw Deployment Must Address
Any OpenClaw setup faces three categories of security risk. Understanding them is the first step toward mitigating them.
1. Host compromise (root risk). OpenClaw runs with user-level privileges and can execute arbitrary shell commands, access the filesystem, and control a browser. If the agent is compromised, so is everything on the host machine. Mitigation: Docker container isolation with security hardening flags.
2. Unintended actions (agency risk). An LLM-powered agent can misinterpret instructions and take destructive actions: deleting files, sending messages to the wrong contact, or modifying documents without authorisation. Mitigation: scoped tool access through fastn UCL, so only the actions you explicitly enable are available to the agent.
3. Credential leakage (keys risk). Standard MCP setups store API keys and OAuth tokens in plaintext environment variables or config files. If the agent or its container is breached, those credentials are exposed. Mitigation: fastn UCL as a credential broker. Tokens never touch the agent. UCL handles OAuth flows, token refresh, and secure storage externally.
Layer 1: Docker Isolation, Containing the Agent
The first line of defence is running OpenClaw inside a Docker container. On macOS and Windows, Docker Desktop provides two layers of isolation: a LinuxKit virtual machine sits between your host OS and the container, and the container itself runs in a restricted namespace.
Clone and build:
git clone --depth 1 https://github.com/openclaw/openclaw.git cd openclaw docker build -t openclaw:local -f Dockerfile .
Create your .env file:
OPENCLAW_CONFIG_DIR=$HOME/.openclaw OPENCLAW_WORKSPACE_DIR=$HOME/.openclaw/workspace OPENCLAW_GATEWAY_PORT=18789 OPENCLAW_BRIDGE_PORT=18790 OPENCLAW_GATEWAY_TOKEN=$(openssl rand -hex 32) OPENCLAW_IMAGE=openclaw:local
Run the onboarding wizard:
docker compose run --rm openclaw-cli onboard --no-install-daemon
During onboarding, choose these security-conscious settings:
- Setup type: local gateway
- Gateway bind: loopback (127.0.0.1), which restricts access to your machine only
- Authentication: token-based
- Skills: skip all, since we will use fastn UCL for integrations
- Chat channels: WebChat only
Start the gateway:
docker compose up -d openclaw-gateway
For production deployments, add these security options to your docker-compose.yml:
security_opt: - no-new-privileges:true # Prevent privilege escalation cap_drop: - ALL # Remove all Linux capabilities read_only: true # Read-only filesystem tmpfs: - /tmp # Writable scratch space, wiped on restart
These flags ensure that even if the agent is compromised, it cannot escalate privileges, write to the filesystem, or acquire additional capabilities. The tmpfs mount provides the minimal writable space the agent needs to function.
Layer 2: fastn UCL, the MCP Gateway for Tool Orchestration and Governance
Docker addresses host compromise. Now we need to solve the harder problems: credential isolation, action governance, and cross-tool orchestration. This is where fastn UCL turns a basic OpenClaw setup into an enterprise-ready deployment.
fastn UCL is a multi-tenant MCP gateway that sits between your AI agent and the tools it accesses. Unlike basic MCP servers that simply expose API endpoints, UCL provides a complete orchestration and security layer:
- Credential brokering. OAuth tokens and API keys are managed entirely by UCL. The agent authenticates through a single gateway URL. No tokens are stored in the agent's environment, config files, or container.
- Scoped actions. You choose exactly which operations each connector supports. Gmail can read and send, but not delete. Google Docs can create and read, but not share.
- Tool orchestration. Access 1,000+ SaaS tools through a single /command endpoint. UCL's context-aware routing reduces context window overhead by 30-40% compared with loading individual MCP server tool schemas.
- Observability. UCL Insights provides a real-time dashboard showing every tool call, every action, and every error, giving you a full audit trail for compliance and debugging.
- Multi-tenant security. Each workspace is isolated with its own credentials, tool access, and audit logs. Different teams, different users, different permissions, one gateway.
Compared with the alternatives: raw MCP servers keep plaintext tokens in environment variables, offer all-or-nothing access, support a single user, load the full schema per tool, and ship with no built-in observability. Gateway vendors typically manage OAuth and add basic filtering and logging, which is good for prototyping. fastn UCL brokers OAuth so tokens never reach the agent, scopes per action with deny-by-default, isolates workspaces natively per tenant, cuts context by 30-40% through orchestration and schema filtering, and provides a real-time audit trail.
Connecting OpenClaw to fastn UCL: Step by Step
Here is how we connected OpenClaw to fastn UCL in our test environment. Every command and config is from our actual hands-on setup.
Step 1: set up your fastn UCL workspace.
- Create a free account at fastn.ai.
- In the Connect section, enable the connectors and tools your agent needs.
- Authenticate each connector through the OAuth flow. fastn handles token storage securely on your behalf.
- Scope your actions. For example, enabling the Gmail connector exposes tools such as getMails, getMail, sendMail, and getMailAttachments.
- At the top you will find your MCP server URL. Copy it. This URL contains your Space ID and API key.
Step 2: install the MCP adapter plugin. The openclaw-mcp-adapter plugin exposes MCP server tools as native OpenClaw agent tools. Install it inside the running container:
docker compose exec openclaw-gateway node dist/index.js \ plugins install \ https://github.com/androidStern-personal/openclaw-mcp-adapter.git
Step 3: configure the plugin. Add the fastn UCL server configuration to your ~/.openclaw/openclaw.json:
{
"plugins": {
"entries": {
"openclaw-mcp-adapter": {
"enabled": true,
"config": {
"servers": [{
"name": "fastn-ucl",
"transport": "http",
"url": "YOUR_FASTN_MCP_SERVER_URL"
}]
}
}
}
}
}Replace YOUR_FASTN_MCP_SERVER_URL with the URL you copied earlier. The URL embeds your Space ID and API key, so the plugin authenticates automatically through fastn's gateway.
Step 4: restart and verify. Use restart, not down and up. The plugin is installed inside the container, so recreating the container would delete it.
docker compose restart openclaw-gateway # Check the logs after a few seconds: docker compose logs openclaw-gateway --tail 20
Once completed, you will see the tools you enabled registered against the gateway:
[mcp-adapter] Connecting to fastn-ucl... [mcp-adapter] fastn-ucl: found 9 tools [mcp-adapter] Registered: fastn-ucl_sendMail [mcp-adapter] Registered: fastn-ucl_getMails [mcp-adapter] Registered: fastn-ucl_getMail [mcp-adapter] Registered: fastn-ucl_createDoc [mcp-adapter] Registered: fastn-ucl_getDocs [mcp-adapter] Registered: fastn-ucl_getDoc [mcp-adapter] Registered: fastn-ucl_updateDoc [mcp-adapter] Registered: fastn-ucl_getMailAttachments
Each registered tool maps to an action you enabled in your UCL workspace. The agent can now call these tools directly through natural language in the OpenClaw chat interface.
Production Readiness Checklist
Before deploying OpenClaw with fastn UCL in a team or production environment, validate these controls:
- Docker: read-only container filesystem (--read-only)
- Docker: all Linux capabilities dropped (--cap-drop=ALL)
- Docker: privilege escalation blocked (no-new-privileges)
- Docker: gateway bound to loopback only (127.0.0.1)
- Docker: token-based gateway authentication enabled
- fastn UCL: connectors scoped to least-privilege actions
- fastn UCL: destructive actions such as delete and share disabled
- fastn UCL: UCL Insights monitoring active
- fastn UCL: workspace isolation per team or tenant
- Network: agent has no direct internet access except the UCL endpoint
From Prototype to Production
OpenClaw is a powerful agent framework, but power without guardrails is a liability. Combining Docker isolation with fastn UCL as your MCP gateway gives you a layered security model:
- Docker contains the agent, preventing host compromise through filesystem restrictions, capability dropping, and privilege escalation blocks.
- fastn UCL governs the agent, ensuring it can only access the tools and actions you explicitly authorise, with credentials that never touch the agent runtime.
- UCL Insights observes the agent, providing a full audit trail of every action taken across every tool, every tenant, every session.
The result is an AI agent that sends emails, reads documents, and orchestrates cross-platform workflows while remaining locked down, governed, and fully observable. That is the difference between a demo and a deployment.
Useful references: fastn UCL documentation at docs.fastn.ai, the fastn MCP server at github.com/fastnai/mcp-fastn, the OpenClaw repository at github.com/openclaw/openclaw, the MCP adapter plugin at github.com/androidStern-personal/openclaw-mcp-adapter, and Docker security best practices at docs.docker.com/engine/security.