Skip to Content
GuidesOpenClaw Agent

Running OpenClaw in a Cage

This guide walks through deploying an OpenClaw  AI agent inside a LobsterCage — from cage creation to a fully autonomous agent that hibernates when idle and wakes on demand.

Prerequisites

  • A LobsterCage account (sign up )
  • The lobster CLI installed (npm install -g lobstercage-cli)
  • An AI provider API key (e.g., Anthropic, OpenAI)
  • A messaging bot token (Telegram, Slack, Discord, etc.)

1. Create and start a cage

lobster deploy my-agent

This creates a Starter-sized cage (1 vCPU, 4 GB RAM, 20 GB storage) and starts it. For heavier workloads:

lobster deploy my-agent --size standard # 2 vCPU, 8 GB lobster deploy my-agent --size power # 4 vCPU, 16 GB

2. Set environment variables

Store your API keys and bot tokens securely — they’re encrypted at rest with AES-256:

# AI provider key lobster env set my-agent ANTHROPIC_API_KEY=sk-ant-... # Messaging bot token (e.g., Telegram) lobster env set my-agent TELEGRAM_BOT_TOKEN=123456:ABC... # Any other secrets your agent needs lobster env set my-agent DATABASE_URL=postgres://...

Verify they’re set:

lobster env list my-agent

3. SSH in and install OpenClaw

lobster ssh my-agent

Inside the cage:

# Install OpenClaw npm install -g openclaw # Verify installation openclaw --version

4. Configure OpenClaw

Create the OpenClaw configuration file:

mkdir -p ~/.openclaw cat > ~/.openclaw/openclaw.json << 'EOF' { "dmPolicy": "open", "allowFrom": ["*"], "env": { "ANTHROPIC_API_KEY": "${ANTHROPIC_API_KEY}" }, "channels": { "telegram": { "botToken": "${TELEGRAM_BOT_TOKEN}" } } } EOF

Adjust the configuration for your messaging platform. OpenClaw supports Telegram, Slack, Discord, Signal, WhatsApp, and more.

5. Set up the webhook

Get your cage’s webhook URL:

lobster status my-agent

The output includes a Webhook URL like:

https://gateway.lobstercage.ai/hook/cage_abc123/tok_xyz/

Register it with your messaging platform. For Telegram:

curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook" \ -H "Content-Type: application/json" \ -d '{"url": "https://gateway.lobstercage.ai/hook/cage_abc123/tok_xyz/"}'

6. Start OpenClaw

# Start the OpenClaw gateway (listens on port 8787 by default) openclaw gateway start

OpenClaw will now:

  • Listen for incoming webhooks on port 8787
  • Route messages to your configured AI provider
  • Respond via the messaging platform

7. Test it

Send a message to your bot on Telegram (or whichever platform you configured). You should get a response from your AI agent within a few seconds.

8. Set up auto-start

To ensure OpenClaw starts automatically when the cage wakes from hibernation, create a startup script:

cat > /workspace/start.sh << 'EOF' #!/bin/bash cd /workspace openclaw gateway start EOF chmod +x /workspace/start.sh

Configure it to run on cage boot by adding to your cage’s init:

# Add to ~/.bashrc or use the cage's init system echo '/workspace/start.sh &' >> ~/.profile

How the lifecycle works

Once everything is configured:

  1. User sends a message → Telegram/Slack/Discord delivers it to your webhook URL
  2. Cage is hibernated? → Gateway proxy buffers the request and wakes the cage
  3. Cage boots (~10-30 seconds) → OpenClaw starts, buffered messages are delivered
  4. Agent responds → AI processes the message, sends a reply
  5. No activity for 30 minutes → Cage auto-hibernates, billing stops

Your agent is always reachable but you only pay for active compute time. A typical agent that handles a few conversations per day costs less than $1/month.

Adding cron jobs

OpenClaw supports scheduled tasks. Configure them in your OpenClaw config to run periodic jobs:

# Check cage's cron schedule lobster ssh my-agent openclaw cron list

LobsterCage automatically wakes your cage 5 minutes before a scheduled cron job, runs it, then hibernates when idle.

Monitoring

# Watch real-time lifecycle events lobster tail my-agent # View recent logs lobster logs my-agent # Check resource usage lobster status my-agent

Tips

  • Workspace persistence: Everything in /workspace and /home/agent survives hibernation. Install packages and configure once.
  • Multiple agents: Run multiple OpenClaw instances in separate cages, each with their own bot and personality.
  • Budget controls: Set spending limits in the dashboard to prevent runaway costs.
  • SSH debugging: Use lobster ssh my-agent anytime to inspect, debug, or update your agent live.