Spaces:
Paused
Paused
File size: 9,323 Bytes
1f287c7 be0042c 1f287c7 be0042c a09f48c 1f287c7 2d5c2cb 1f287c7 a09f48c be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c 1f287c7 be0042c a09f48c 1f287c7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | #!/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
|