# Security for AI code review and coding agents

URL: https://codepanel.ai/security

How CodePanel isolates coding agents with OS sandboxes, keeps API keys off laptops, pins MCP tools with SHA-256, and blocks prompt injection.

CodePanel separates credentials from execution on both sides of the loop. Provider API keys stay encrypted on the backend and never reach developer laptops or agent contexts; local coding agent commands run inside an OS sandbox over isolated git worktrees; external MCP tools are pinned by SHA-256 hash; and pull request reviews sanitize hostile input before any model reads it.

## Local coding agent sandboxing

When the [desktop app](/download) runs a coding agent on your machine, every shell command, check, stdio MCP server, and external CLI runs inside the operating system sandbox (`sandbox-exec` on macOS, `bwrap` on Linux):

- **Write confinement:** Commands can write only to the run's dedicated git worktree, its own temporary/home directory, and the exact `.git` paths required to commit on the run's branch (`worktrees/<run>/`, `objects/`, and its own ref). Moving `main` or another branch is denied.
- **Credential and sibling isolation:** Reads of `~/.ssh`, cloud and `gh` credentials, `~/.codepanel` (the runner's token and other runs' worktrees), keychains, and other local checkouts fail at the OS level.
- **Offline autopilot runs:** Rule-started runs have no network access by default, including dependency installation, unless explicitly enabled per repository in the runner's own `config.json`.
- **Fail-closed startup proof:** The runner verifies the sandbox at startup and refuses to run commands if no working sandbox is available unless you explicitly opt out.
- **Credential warnings:** If a checkout's `.git/config` contains an embedded token or inline credential helper, Settings and the run log warn you where it is without printing the secret.

On macOS, measured on an Apple M1 Pro (n = 100 interleaved), the OS sandbox adds 10.4 ms median (12.1 ms p95) per command.

## Zero provider keys on developer laptops

Provider API keys are entered only in the browser, encrypted at rest with AES-256-GCM, and decrypted only inside backend actions:

- **Model proxy:** Local coding runs authenticate with short-lived run tokens pointed at CodePanel's model proxy. The proxy attaches your stored key (or platform credits), enforces per-task and daily caps, and forwards the request. Neither the runner nor any external CLI ever sees a provider API key.
- **Loopback pairing:** The desktop shell generates a fresh 32-byte pairing secret and writes it to the local runner sidecar's `stdin` at startup (never via CLI args or env vars, which `ps` can expose), closing first-to-connect hijacking on `127.0.0.1`.
- **Hooks-off publishing:** Git push and `gh pr create` run in the runner after the agent stops, with git hooks disabled so code written by the agent cannot execute as you during push.

## MCP tool pinning and data boundaries

Connecting external MCP servers to autonomous agents introduces two risks: a server rewriting a tool description after approval (a rug pull), and production data leaking to non-compliant models. CodePanel enforces both in code:

- **SHA-256 tool pinning:** Every approved MCP tool is pinned by a canonical SHA-256 hash of its name, description, and schemas. If a server changes a tool definition after approval, the tool is dropped until the owner approves it again.
- **Explicit read-only marking:** Production connections only expose tools the owner explicitly marked read-only; server self-annotations are never trusted on their own.
- **Repository `.mcp.json` as proposal only:** Configs committed in a repository are never started automatically.
- **Production data boundaries:** A repository run contract can list MCP connections that read production data. Runs holding those tools start only on approved zero-retention providers and never on external agent CLIs; if the account's AI Gateway is unreachable, production-read runs stop (`gateway_unreachable`) instead of falling back to direct calls.

## Owner-confirmed scopes for agent tokens

When an agent requests an API token via device login or OAuth 2.1 (PKCE S256), scopes that widen what an agent can do unattended are unticked by default and dropped unless the owner explicitly checks them:

| Owner-confirmed scope | Why it stays unticked by default |
| --- | --- |
| `interrupts:answer` | Prevents an agent from approving its own permission prompts. |
| `rules:write` | Prevents an agent from widening its own command or review rules. |
| `agents:write` | Prevents an agent from editing agent definitions or lifting an owner's "Stop everything" pause. |
| `budget:write` | Prevents an agent from raising spend caps or enabling auto-reload. |

Personal tokens (`cpk_`) and OAuth tokens (`cpo_`) are stored only as SHA-256 hashes and can be revoked immediately in Settings.

## Prompt injection defenses in code review

Pull request titles, descriptions, diffs, comments, and linked issues are untrusted input. Before any reviewer model runs, CodePanel applies layered defenses documented in [Security docs](/docs/security):

- **Strict fencing and hidden-text stripping:** HTML comments, Unicode tag characters, and bidirectional overrides are stripped from PR metadata before reaching models, and shown as visible escapes inside code.
- **Secret masking:** Credential files (`.env`, `*.pem`, `id_rsa`) are never read outside the diff, and known key prefixes (AWS, GitHub, Slack, Stripe, Google, private key blocks) are masked before model dispatch while keeping line numbers intact.
- **Output sanitization:** Model-written comments strip images, HTML comments, untrusted links, download-piped shell commands, and `@` mentions before posting to GitHub.
- **Signed webhooks and replay protection:** Every GitHub webhook is verified with constant-time `HMAC-SHA256` against the exact raw body before any job is scheduled, with 7-day delivery replay protection.

Read the full technical reference in [Security documentation](/docs/security) and [Desktop app sandbox details](/docs/desktop-app#the-sandbox).
