2026-09-21 10:31:36 +03:00
|
|
|
#!/bin/bash
|
2026-10-23 10:11:39 +00:00
|
|
|
# Bootstrap: enforce the sandbox cli-config and verify the cursor-agent
|
2026-09-21 10:31:36 +03:00
|
|
|
# binary works before the HTTP server starts serving traffic.
|
2026-10-23 10:11:39 +00:00
|
|
|
#
|
|
|
|
|
# The config is FORCE-REWRITTEN on every boot. The agent CLI rewrites
|
|
|
|
|
# ~/.cursor/cli-config.json at runtime (model choice, permission dialogs
|
|
|
|
|
# auto-answered in the past, etc.); with HOME on a PVC a drifted config
|
|
|
|
|
# (observed 2026-10: allow-all Shell/Read/Write) would survive reboots
|
|
|
|
|
# forever. Rewriting on boot pins the security-relevant fields.
|
2026-09-21 10:31:36 +03:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
CURSOR_HOME="${HOME}/.cursor"
|
|
|
|
|
BOOTSTRAP="/opt/cursor-bootstrap"
|
|
|
|
|
export NO_OPEN_BROWSER=1
|
|
|
|
|
|
|
|
|
|
mkdir -p "${CURSOR_HOME}"
|
|
|
|
|
|
2026-10-23 10:11:39 +00:00
|
|
|
# Force-rewrite the security config every boot (merge model preference if
|
|
|
|
|
# the runtime config has one, keep everything else from the bootstrap file).
|
|
|
|
|
# Written to BOTH the proxy HOME and the sandboxed agent HOME — the ACP
|
|
|
|
|
# children read the latter.
|
|
|
|
|
write_config() {
|
|
|
|
|
local target_home="$1"
|
|
|
|
|
mkdir -p "${target_home}/.cursor"
|
|
|
|
|
if [[ -f "${BOOTSTRAP}/cli-config.json" ]]; then
|
|
|
|
|
local model_json="{}"
|
|
|
|
|
if [[ -f "${target_home}/.cursor/cli-config.json" ]]; then
|
|
|
|
|
model_json=$(node -e '
|
|
|
|
|
try {
|
|
|
|
|
const cur = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
|
|
|
|
|
if (cur.model) console.log(JSON.stringify({ model: cur.model }));
|
|
|
|
|
else console.log("{}");
|
|
|
|
|
} catch { console.log("{}"); }
|
|
|
|
|
' "${target_home}/.cursor/cli-config.json" 2>/dev/null || echo '{}')
|
|
|
|
|
fi
|
|
|
|
|
node -e '
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const base = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
|
|
|
const extra = JSON.parse(process.argv[2] || "{}");
|
|
|
|
|
const out = { ...base, ...extra };
|
|
|
|
|
fs.writeFileSync(process.argv[3], JSON.stringify(out, null, 2) + "\n");
|
|
|
|
|
' "${BOOTSTRAP}/cli-config.json" "${model_json}" "${target_home}/.cursor/cli-config.json"
|
|
|
|
|
fi
|
|
|
|
|
# Drop runtime-written hook config: hooks execute arbitrary commands from
|
|
|
|
|
# the agent's HOME; we never want agent-authored hooks in this deployment.
|
|
|
|
|
if [[ -f "${target_home}/.cursor/settings.json" ]]; then
|
|
|
|
|
node -e '
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const p = process.argv[1];
|
|
|
|
|
try {
|
|
|
|
|
const s = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
|
|
|
if (s.hooks) { delete s.hooks; fs.writeFileSync(p, JSON.stringify(s, null, 2) + "\n"); }
|
|
|
|
|
} catch { /* leave broken file alone */ }
|
|
|
|
|
' "${target_home}/.cursor/settings.json"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write_config "${HOME}"
|
|
|
|
|
if [[ -n "${CURSOR_AGENT_HOME:-}" && "${CURSOR_AGENT_HOME}" != "${HOME}" ]]; then
|
|
|
|
|
write_config "${CURSOR_AGENT_HOME}"
|
2026-09-21 10:31:36 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# cursor-agent auth via env (no interactive login).
|
|
|
|
|
if [[ -z "${CURSOR_API_KEY:-}" ]]; then
|
|
|
|
|
echo "CURSOR_API_KEY is not set" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
export CURSOR_API_KEY
|
|
|
|
|
|
|
|
|
|
# cursor-agent itself must respond.
|
|
|
|
|
if ! /usr/local/bin/agent.real --version >/dev/null 2>&1; then
|
|
|
|
|
echo "cursor-agent binary is not executable" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2026-10-23 10:11:39 +00:00
|
|
|
echo "cursor-agent bootstrap: sandbox config enforced, auth ok, agent responds"
|