#!/bin/bash # entrypoint.sh — start outbound proxy, write config, launch ZeroClaw set -euo pipefail # ── Defaults ────────────────────────────────────────────────────────────────── ZEROCLAW_MODEL="${ZEROCLAW_MODEL:-meta-llama/llama-3.3-70b-instruct:free}" OPENROUTER_API_KEY="${OPENROUTER_API_KEY:-}" OLLAMA_CLOUD_API_KEY="${OLLAMA_CLOUD_API_KEY:-}" GH_TOKEN="${GH_TOKEN:-}" TRELLO_API_KEY="${TRELLO_API_KEY:-}" TRELLO_TOKEN="${TRELLO_TOKEN:-}" HOSTINGER_API_TOKEN="${HOSTINGER_API_TOKEN:-}" # Google Calendar/Tasks MCP - set to path of token JSON injected via secret GOOGLE_TOKEN_FILE="${GOOGLE_TOKEN_FILE:-}" # ALLOWED_IPS: comma-separated CIDRs/IPs allowed to access ZeroClaw (empty = allow all) ALLOWED_IPS="${ALLOWED_IPS:-}" # REDIRECT_URL: where non-whitelisted visitors are sent (302) REDIRECT_URL="${REDIRECT_URL:-https://overbyte.ee}" # ── 1. Start tinyproxy (outbound allowlist) ─────────────────────────────────── # Generate the config at runtime to guarantee LF line endings (no CRLF issues). # tinyproxy 1.11.x on Debian trixie: no User/Group, no MinSpareServers etc. cat > /tmp/tinyproxy.conf << 'TINYPROXY_EOF' Port 8888 Listen 127.0.0.1 Timeout 90 MaxClients 32 LogLevel Error Logfile "/dev/stderr" Filter "/etc/tinyproxy/allowlist" FilterDefaultDeny Yes FilterURLs Off TINYPROXY_EOF # Strip any stray CR from the allowlist (created on Windows) sed -i 's/\r//' /etc/tinyproxy/allowlist tinyproxy -c /tmp/tinyproxy.conf echo "[entrypoint] tinyproxy started (allowlist-only outbound filter)" # Point all HTTP clients at the local proxy export HTTP_PROXY="http://127.0.0.1:8888" export HTTPS_PROXY="http://127.0.0.1:8888" export http_proxy="http://127.0.0.1:8888" export https_proxy="http://127.0.0.1:8888" # Local traffic must bypass the proxy export NO_PROXY="localhost,127.0.0.1" export no_proxy="localhost,127.0.0.1" # ── 2. nginx inbound IP firewall ───────────────────────────────────────────── # ZeroClaw binds on 127.0.0.1:7861; nginx fronts on 0.0.0.0:7860. # ALLOWED_IPS controls inbound access; non-matching IPs → 302 REDIRECT_URL. # HF's proxy appends the real client IP as the rightmost X-Forwarded-For entry; # set_real_ip_from 0.0.0.0/0 + real_ip_recursive off extracts it correctly. if [ -z "$ALLOWED_IPS" ]; then GEO_DEFAULT=1 GEO_ENTRIES="" else GEO_DEFAULT=0 GEO_ENTRIES="" IFS=',' read -ra _ALLOW_IPS <<< "$ALLOWED_IPS" for _IP in "${_ALLOW_IPS[@]}"; do _IP="$(echo "$_IP" | xargs)" [ -n "$_IP" ] && GEO_ENTRIES="${GEO_ENTRIES} ${_IP} 1;\n" done fi { printf 'events {}\nhttp {\n' printf ' set_real_ip_from 0.0.0.0/0;\n' printf ' real_ip_header X-Forwarded-For;\n\n' printf ' geo $remote_addr $is_allowed {\n' printf " default %s;\n" "$GEO_DEFAULT" printf '%b' "$GEO_ENTRIES" printf ' }\n\n' printf ' server {\n' printf ' listen 7860;\n\n' printf ' location / {\n' printf ' if ($is_allowed = 0) {\n' printf " return 302 %s;\n" "$REDIRECT_URL" printf ' }\n' printf ' proxy_pass http://127.0.0.1:7861;\n' printf ' proxy_http_version 1.1;\n' printf ' proxy_set_header Upgrade $http_upgrade;\n' printf ' proxy_set_header Connection "upgrade";\n' printf ' proxy_set_header Host $host;\n' printf ' proxy_set_header X-Real-IP $remote_addr;\n' printf ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n' printf ' proxy_read_timeout 3600;\n' printf ' }\n' printf ' }\n' printf '}\n' } > /tmp/nginx.conf nginx -c /tmp/nginx.conf -t 2>&1 nginx -c /tmp/nginx.conf echo "[entrypoint] nginx started on :7860 (firewall: ALLOWED_IPS='${ALLOWED_IPS:-all}')" # ── 3. dbus (required by Chromium / agent-browser) ──────────────────────────── dbus-daemon --system --fork 2>/dev/null || true # ── 4. Directories ───────────────────────────────────────────────────────────── mkdir -p /zeroclaw-data/.zeroclaw /zeroclaw-data/workspace # ── 5. Validate LLM backend ────────────────────────────────────────────────── if [ -n "$OLLAMA_CLOUD_API_KEY" ]; then LLM_PROVIDER="ollama" LLM_API_KEY="$OLLAMA_CLOUD_API_KEY" # Export so ZeroClaw's Ollama provider picks it up from env export OLLAMA_API_KEY="$OLLAMA_CLOUD_API_KEY" export OLLAMA_CLOUD_API_KEY echo "[entrypoint] LLM: Ollama cloud" elif [ -n "$OPENROUTER_API_KEY" ]; then LLM_PROVIDER="openrouter" LLM_API_KEY="$OPENROUTER_API_KEY" echo "[entrypoint] LLM: OpenRouter" else LLM_PROVIDER="openrouter" LLM_API_KEY="" echo "WARN: no LLM API key set (OPENROUTER_API_KEY or OLLAMA_CLOUD_API_KEY)" >&2 fi # ── 6. Write config.toml ────────────────────────────────────────────────────── cat > /zeroclaw-data/.zeroclaw/config.toml << TOML schema_version = 2 default_provider = "${LLM_PROVIDER}" api_url = "https://openrouter.ai/api/v1" api_key = "${LLM_API_KEY}" default_model = "${ZEROCLAW_MODEL}" default_temperature = 0.7 workspace_dir = "/zeroclaw-data/workspace" [gateway] port = 7861 host = "127.0.0.1" allow_public_bind = false require_pairing = true session_persistence = true session_ttl_hours = 0 idempotency_max_keys = 10000 idempotency_ttl_secs = 300 pair_rate_limit_per_minute = 10 webhook_rate_limit_per_minute = 60 trust_forwarded_headers = false [gateway.pairing_dashboard] code_length = 8 code_ttl_secs = 3600 lockout_secs = 300 max_failed_attempts = 5 max_pending_codes = 3 [autonomy] level = "supervised" auto_approve = ["file_read", "file_write", "file_edit", "memory_recall", "memory_store", "web_search_tool", "web_fetch", "calculator", "glob_search", "content_search", "image_info", "weather", "git_operations", "browser", "browser_open"] allowed_commands = ["git", "npm", "cargo", "ls", "cat", "grep", "find", "echo", "pwd", "wc", "head", "tail", "date", "python", "python3", "pip", "node"] allowed_roots = ["/zeroclaw-data"] block_high_risk_commands = true forbidden_paths = ["/etc", "/root", "/home", "/usr", "/bin", "/sbin", "/lib", "/opt", "/boot", "/dev", "/proc", "/sys", "/var", "/tmp"] max_actions_per_hour = 60 max_cost_per_day_cents = 500 require_approval_for_medium_risk = true workspace_only = true shell_timeout_secs = 60 [browser] allowed_domains = ["*"] backend = "agent_browser" enabled = true native_headless = true [browser.computer_use] allow_remote_endpoint = false timeout_ms = 15000 [cron] catch_up_on_startup = true enabled = true max_run_history = 50 [mcp] enabled = true deferred_loading = true [[mcp.servers]] name = "github" transport = "stdio" command = "/usr/local/bin/github-mcp-server" args = ["stdio", "--toolsets=all"] env = { "GITHUB_PERSONAL_ACCESS_TOKEN" = "${GH_TOKEN}" } [[mcp.servers]] name = "trello" transport = "stdio" command = "npx" args = ["-y", "mcp-server-trello"] env = { "TRELLO_API_KEY" = "${TRELLO_API_KEY}", "TRELLO_TOKEN" = "${TRELLO_TOKEN}" } [[mcp.servers]] name = "hostinger" transport = "stdio" command = "npx" args = ["-y", "hostinger-api-mcp"] env = { "API_TOKEN" = "${HOSTINGER_API_TOKEN}" } [[mcp.servers]] name = "browser" transport = "stdio" command = "/usr/local/bin/browser-mcp" args = [] env = { "AGENT_BROWSER_EXECUTABLE_PATH" = "/usr/bin/chromium", "AGENT_BROWSER_ARGS" = "--no-sandbox,--disable-dev-shm-usage,--disable-setuid-sandbox,--disable-gpu" } TOML # Conditionally append Google Calendar/Tasks MCP if [ -n "$GOOGLE_TOKEN_FILE" ] && [ -f "$GOOGLE_TOKEN_FILE" ]; then cat >> /zeroclaw-data/.zeroclaw/config.toml << GCAL [[mcp.servers]] name = "google-workspace" transport = "stdio" command = "/opt/gcal-venv/bin/python3" args = ["/opt/gcal_server.py"] env = { "GOOGLE_TOKEN_FILE" = "${GOOGLE_TOKEN_FILE}" } GCAL echo "[entrypoint] google-workspace MCP enabled (${GOOGLE_TOKEN_FILE})" else echo "[entrypoint] google-workspace MCP disabled (set GOOGLE_TOKEN_FILE secret to enable)" fi echo "[entrypoint] config.toml written" echo "[entrypoint] provider : ${LLM_PROVIDER} / ${ZEROCLAW_MODEL}" echo "[entrypoint] listen : nginx:7860 -> zeroclaw:7861" echo "[entrypoint] browser : agent-browser + Chromium (MCP server: browser)" echo "[entrypoint] filter : ALLOWED_IPS='${ALLOWED_IPS:-all}' REDIRECT=${REDIRECT_URL}" echo "[entrypoint] pairing required - check logs for PIN" exec zeroclaw daemon