AI Coding Agent Security: Egress, Keys, Audit

Formal Endpoint runs on the laptop or inside the Cursor Cloud Agent or Devin VM, recognizes each coding agent by the process that opens a connection, and applies policy to what it sends: which hosts, which pushes and merges, which API keys, and which engineer the log names.

endpoint · github-agent-gitexample
# pre_tcp: process.has_agent_ancestor
AGENT  claude → git push → ssh  github.com:22
AGENT  Cursor → ssh  ssh.github.com:443
HUMAN  git push from the engineer's own terminal: no agent ancestor
# rule not matched: the connection passes through untouched

The problem

What are the biggest AI coding agent risks?

When Claude Code runs git push, GitHub sees the engineer’s SSH key, laptop and IP address, and nothing in the connection says an agent typed the command. Our approach to AI coding agent security starts from telling the two apart. The biggest risks come from an agent using its engineer’s access for something the task didn’t need. Prompt injection is often how one starts: instructions in a README, a code comment or a tool result that the agent follows. OWASP calls the underlying flaw excessive agency, an agent holding more permissions and reach than its job requires. We’d rather check the push than try to spot every injected prompt, because the push looks the same on the wire whatever talked the agent into it.

  1. Agents run as the engineer

    A push to a repository that should only take human commits goes out with the engineer's own SSH key.

  2. Keys in .env files and clone URLs

    An API call made with a key the agent found in .env, or a token pasted into a clone URL.

  3. Pushes and merges nobody reviewed

    An auto-merge on a pull request nobody read, from a cloud agent run nobody can trace to a person.

today · no policy on the pathexample
01
claude-code · leogit push acme/infrastructureALLOWED
02
claude-code · leocurl api.stripe.com with the key from .envALLOWED
03
cloud agent · no named ownerenablePullRequestAutoMerge acme/app #42ALLOWED

# A call to an MCP server nobody approved goes through the same way. Compromised or just wrong, the agent does its damage over a connection it opens.

Definition

What is AI coding agent security?

AI coding agent securitynoun

AI coding agent security is the set of controls on what coding agents and AI coding assistants such as Claude Code, Codex, Cursor and Devin can reach, which credentials they can use, which of their actions need a person, and whose name goes on each request.
  • The agent at runtime

    It covers the agent on a developer’s laptop or in a cloud VM, rather than the code it produces. An AI coding agent security platform puts the controls where the actions happen.

  • Not the old AI coding assistant security

    That meant an autocomplete that suggests code a developer accepts or rejects. Review works for that. It stops working once the tool runs the tests, installs the package and pushes the branch on its own, because by the time anyone reviews, the actions already happened.

  • Not code scanning

    SAST, dependency scanning and the AI fix agents built on them check what the agent wrote. Formal doesn’t scan code. It sits on the connections, next to whatever scanner you run.

  • One kind of AI agent

    Coding agents are one part of AI agent security, which covers the others with the same Endpoint.

Inside vs outside

Controls inside the agent, and controls outside it

Claude Code ships real controls: permission prompts, Bash allowlists, a sandbox and hooks. Use them. They’re settings of the agent, though, so whoever edits those settings edits the controls (what still applies with --dangerously-skip-permissions). Our engineers found the gaps by trying: allowlisting Bash commands and proxies and Claude Code. Keep the in-agent controls for speed and to cut down on prompts, and put the checks you’d show an auditor on the network path, where the agent’s configuration has no say.

Inside the agentOutside it, with Formal
What it isPermission prompts, Bash allowlists, the sandbox and hooksNetwork rules and Rego policies on the connection the agent opens
Who can change itWhoever edits settings.json, or starts a session that skips permissionsRules and policies live in the Control Plane, out of the agent's settings
Bash allowlistAllowlisting go test allows any command: the agent can edit a test file to call exec.CommandSees the connections the agent and the processes it spawns open
Domain allowlistAnthropic's devcontainer firewall allows hosts by IP address, so it can't tell a clone from a push, or an upload from a downloadReads the push itself, over SSH and HTTPS, and lets the clone through
HooksSee the tool call before it runs; we tested where they fail open and who can turn them offChecks the request on the wire, whatever tool call produced it
Use it forSpeed, and fewer promptsThe checks you'd show an auditor

Agent or engineer

Telling the agent from the engineer on one laptop

Transparent Mode hooks Formal Endpoint into the operating system’s networking (a Network Extension on macOS), so Claude Code and the tools it runs need no proxy settings. Network rules written in CEL decide which of those connections Formal inspects, in up to three stages. This one, from the docs recipe for blocking agent pushes, selects git traffic to GitHub from any known agent. Claude Code and its engineer share a user, a device and an IP address, so the rule looks at the process and its ancestors instead.

  • pre_tcp runs before the connection is diverted and sees the process that opened it, plus its ancestors. On macOS, the Endpoint compares each process’s code identifier, bundle identifier and signing team against the known agent identities table
  • process.has_agent_ancestor is true for a known agent and for anything it spawned: Claude Code doesn’t push code itself, it runs git, which runs ssh or git-remote-https. A binary signed by another team doesn’t match
  • pre_tls narrows the rule to GitHub’s hosts, and post_tls keeps HTTP and SSH once Formal has classified the protocol
  • The engineer’s own terminal has no agent in its process tree, so the same push typed by hand never matches. A tool missing from the table matches no agent rule and isn’t intercepted
  • process.is_claude_cli, process.is_codex_cli_rs and process.is_cursor each select a single agent. On Linux there’s no code signature, so these flags match process names (claude, codex), and the ancestor-based push recipe is macOS only
Write network rules ›
network rule · github-agent-gittext
{
  "condition": {
    "pre_tcp": process.has_agent_ancestor,
    "pre_tls": hostname in ["github.com", "ssh.github.com"],
    "post_tls": technology in ["http", "ssh"]
  }
}

How it works

How AI coding agent security works with Formal

Each step has a docs guide: install on Linux, write network rules, block agent git pushes and the cloud agents guide.

  1. Step 1 of 4

    Install the Endpoint

    Push the macOS app with MDM, install the headless package on Debian or Ubuntu, bake it into the Cursor Cloud Agent or Devin environment, or run it as a Kubernetes or ECS sidecar.

    WHERE IT RUNSexample
    • macOS app, pushed with MDM✓
    • Headless package on Debian or Ubuntu✓
    • Cursor, Devin, Kubernetes or ECS✓
  2. Step 2 of 4

    Select agent traffic

    A CEL network rule decides which connections the Endpoint intercepts, such as every flow from a known agent or its children to github.com. A connection no rule matches passes through and isn't logged.

    WHO OPENED THE CONNECTIONexample
    • claude → git → ssh github.comAGENT
    • Cursor → ssh ssh.github.comAGENT
    • git push from leo's terminalHUMAN
  3. Step 3 of 4

    Enforce policy

    Rego policies allow or block each session and request, or pause the agent until the engineer confirms with MFA. Run a policy in Dry-run first to see what it would stop.

    POLICY DECISIONSexample
    • git clone acme/infrastructureALLOWED
    • git push acme/infrastructure, mfa actionREQUESTED
    • new rule in Dry-run: would blockDRY RUN
  4. Step 4 of 4

    Review by person

    Intercepted requests land in Logs with the policy decision and the engineer's identity, or the agent's machine user and its owner for a cloud run. Forward them to your SIEM.

    LOGSexample
    • claude-code on leo-mbpLEO
    • cursor cloud agent · owner_emailMAYA
    • devin · requesting_user_emailSAM

Pushes

Blocking agent pushes, not engineer pushes

Git reaches GitHub three ways: SSH on port 22, SSH on port 443 at ssh.github.com, and HTTPS. A control that covers only one of them is bypassed by changing the remote URL. The block agent git pushes policy reads the push from both protocols: one network rule and one Rego policy stop agent pushes over SSH and HTTPS, while clones and the engineer’s own pushes go through (macOS). The SSH half, from the docs:

  • Over SSH, a push runs git-receive-pack on the server, and a session rule finds it in input.ssh.command
  • Over HTTPS it’s a POST to /git-receive-pack, which a request rule reads from input.http
  • Clones and fetches use git-upload-pack and keep working
  • The repository match is a substring, so listing acme/infrastructure also blocks acme/infrastructure-docs. Usually that’s what you want; check the list before you activate it
  • If a hard block is too strict, the mfa action pauses the agent on the push until the engineer approves it on their device
  • To test it, ask Claude Code to clone a protected repository, change the README, commit and push: the clone succeeds, the push fails with a Formal block message, and the same push from your terminal goes through
Block agent git pushes ›
block-agent-git-pushes.regorego
session := block if {
  input.resource.hostname in hostnames
  contains(input.ssh.command, "git-receive-pack")
  some repository in repositories
  contains(input.ssh.command, repository)
}

On the agent's connections

What the Endpoint does on the agent's connections

Select the agent, hold the key, keep merges with people.

Keys held at the proxy

How do you keep API keys and tokens away from coding agents?

Keep the credential on a Formal Connector and let the proxy add it after the request has left the agent. The Endpoint forwards selected requests with the engineer’s Formal identity, a Native User sets the header, and the laptop or agent VM never stores the key. In our Anthropic walkthrough, Claude Code runs with ANTHROPIC_API_KEY=sk-ant-dummy, and the API answers as if that were a valid key.

  • Keep Stripe API keys off laptops stores the Stripe key as an environment variable on the Connector, builds the Authorization: Bearer header from it, and adds a policy that lets one group read balances, charges and customers while blocking refunds and every other write
  • Verify Full checks the certificate of api.stripe.com before the key goes out
  • Using proxies to hide secrets from Claude Code walks through the Anthropic version with Terraform
  • In a Cursor Cloud Agent or Devin sandbox, the headless Endpoint forwards the same calls to the Connector under the agent’s OIDC identity, and env | grep -i stripe inside the sandbox comes back empty
http · api.stripe.comexample
curl (agent) for leoGET /v1/balance, no Authorization headerTOKEN INJECTED
leo · payments-engineersGET /v1/balanceALLOWED
curl (agent) for leoPOST /v1/charges, not in the read-only policyBLOCKED
Git tokens

Tokens in clone URLs

Git tokens are harder, because agents put them in commands. Clone with https://x-access-token:$GITHUB_TOKEN@github.com/acme/app.git and the shell expands the variable after the tool call, so the real token lands in the command lines of git and git-remote-https, which the Endpoint records in the session log for intercepted connections.

session log · leo-mbpexample
claude-code for leo> git clone https://x-access-token:$GITHUB_TOKEN@github.com/acme/app.git
processcommand line
gitencrypted on device
git-remote-httpsencrypted on device
2 rows · policy log schema: protect git tokensMASKED
Egress per agent

Give Codex its model and your MCP servers, nothing else

Codex Desktop can open a browser to search the web on its own. The Codex Desktop recipe keeps it on its model and the MCP servers you named: the rule looks for the com.openai.codex bundle ID anywhere in the process tree, and the policy refuses everything else with a reason the agent can read.

  • Named servers: add one Formal MCP resource per approved server; the policy lets only those names through
  • Agent type: the policy reads input.agent.type, which the Endpoint sets to Codex Desktop from the User-Agent
  • Your own browser: a browser Codex launched is logged under Codex Desktop; the same site in your own browser has no Codex ancestor and isn’t intercepted
logs · agent: Codex Desktopexample
Codex Desktopresource.technology:llm, prompt with no web searchALLOWED
Codex Desktopresource.technology:mcp, web-search-mcpALLOWED
browser launched by CodexDirect web access blocked: use an approved MCP serverBLOCKED
Cloud agents

Cloud coding agents and the person behind each run

A cloud agent has no laptop and often no single user: anyone on the team can start one from Slack, Linear or GitHub. The headless Endpoint, baked into the Cursor Cloud Agent or Devin environment, signs in with the OIDC token the platform issues for each run, so no Formal API key is stored in the sandbox. It fails closed and logs every request under the agent’s machine user and the engineer the token names (claims.owner_email for Cursor, claims.requesting_user_email for Devin).

  • Merges: the merge policy parses each GitHub GraphQL request, named and inline fragments included, and blocks enablePullRequestAutoMerge, enqueuePullRequest and mergePullRequest, plus the REST merge call; the agent can still open and update pull requests
  • Machine user: a Control Plane Permission denies every Formal API except Endpoint sign-in and logging, so the agent can’t edit its own rules
  • Rollout: create the policy in Draft or Dry-run, review the matches, then set it to Active
  • Identity: Formal verifies the machine identity cryptographically, while the engineer’s identity is asserted by the agent platform
  • At Cursor: the security team used to keep Cloud Agents away from internal systems, since nothing could scope an agent’s reach or name who was behind it; today each Cloud Agent signs in as its own limited Formal identity, and Formal attaches the employee who launched the task to every request (case study)
  • AI agent sandboxes covers that setup and the sandboxes you run yourself in Kubernetes or ECS; giving cloud agents production access with OIDC is how we use it on our own infrastructure
github · cloud agentexample
Cursor Cloud Agent for mayaGET api.github.com/repos/acme/app/pulls/42ALLOWED
Cursor Cloud Agent for mayaPOST /graphql enablePullRequestAutoMergeBLOCKED
Cursor Cloud Agent for mayaPUT /repos/acme/app/pulls/42/merge: 403, Cloud agents cannot merge pull requestsBLOCKED
MCP and skills

MCP servers and skills the agent loads

An MCP server or a skill is part of the agent’s supply chain: it changes what a coding agent can do, and which sensitive data it can reach, without touching its code. Because the Endpoint classifies MCP and LLM traffic, a rule on known agents feeds Formal’s AI governance pages.

  • The Catalog lists the approved MCP servers and skills, with who may use each one
  • Shadow AI review shows the ones people use anyway (skills are detected in Claude Code traffic), and Guardrails decide what happens to those meanwhile
  • Those pages read logs, so they only show traffic that goes through the Endpoint or a Connector
  • Shadow AI detection covers discovery of unapproved servers and skills, and the MCP gateway covers per-tool access to the approved ones
endpoint · ai governanceexample
claude-code for leoMCP server in the Catalog for leoALLOWED
claude-code for leoskill not in the Catalog: Shadow AI reviewREVIEW
codex for mayaunapproved MCP server, Guardrail set to blockBLOCKED

Coverage

Claude Code, Cursor, OpenAI Codex and Devin

Each tool has its own quirks; the network rules and policies above apply to all of them. Claude Code security covers its network reach, the .env files and environment variables it can read, usage monitoring, and the skills and MCP servers it loads; if your engineers point it at other models, we tested Claude Code Router on a work laptop. Cursor security covers Cursor’s agent in the editor and as Cursor Cloud Agents. There’s no OpenAI Codex security page yet: the Endpoint recognizes Codex by signature on macOS and by the codex process name on Linux, and Restrict Codex Desktop to LLM and MCP is its recipe. Devin security covers the OIDC sign-in, just-in-time database access and egress, with each action mapped to the person who started the session. GitHub Copilot appears in the known agent table as Copilot CLI and Copilot for Xcode; the editor extensions aren’t listed there.

Known agent identities ›

Architecture

Coding agents and where they run

Laptops, cloud agent VMs and your own sandboxes. On laptops, Transparent Mode on macOS and Linux, with rules that select agent processes, so the engineer’s own terminal and browser stay off the agent’s path. In cloud agents, the headless Debian package, installed with the environment image, signs in over OIDC and runs Transparent Mode set to fail closed. In your own sandboxes, a native sidecar in Kubernetes Pods or a sidecar container in ECS tasks runs the policies you wrote for laptops.

Formal Endpoint architecture: an egress proxy on laptops, VMs and agent sandboxes that applies network rules and Rego policies before AI agent traffic reaches LLM providers, MCP servers and SaaS APIs.
Formal Endpoint sits in the agent's path and applies policy before a request leaves the machine.

Buyer's checklist

What should an AI coding agent security platform enforce?

Controls the agent can’t edit. It should tell the agent from its engineer on the same machine, keep credentials out of the agent’s environment, name a person for each cloud run, and let you test a rule before it blocks anyone. These are the questions worth asking any vendor that offers to secure AI coding agents, Formal included.

  1. Where does enforcement run?

    In the agent’s settings, an IDE extension, the operating system’s network layer, or a gateway in your network? Formal: at runtime in the network layer on macOS and Linux, in cloud agent VMs and in Kubernetes and ECS sidecars.

  2. Does it block the action, or alert afterwards?

    Formal: a block or an MFA pause on the connection itself, with Logs for review afterwards.

  3. Does a rule see the process that opened the connection?

    Including children like git and ssh. Formal: process identity from code signatures on macOS and process names on Linux.

  4. Can the agent use a credential without ever holding it?

    Formal: a Native User on the Connector adds the credential after the request has left the laptop or the agent VM.

  5. Does each cloud run carry the identity of whoever started it?

    And does the sandbox fail closed when it can’t reach its backend? Formal: the run’s owner claim maps to a Formal user, and the cloud agent guides set the Endpoint to fail closed.

  6. Can a policy run in dry-run, and what does the agent see when it's blocked?

    Formal: Dry-run first; a blocked request returns Formal’s message with the policy, session and request IDs.

  7. Which agents, platforms and protocols aren't covered?

    Formal: tools outside the known agent table aren’t intercepted, the ancestor-based push recipe is macOS only, and there’s no code scanning.

Running cloud agents against our own infrastructure taught our engineers to model agent access as a temporary delegation from a named person, and that’s the shape these controls give it.

Deployment

Runs in your environment: engineer laptops, cloud agent VMs and your own sandboxes

One Endpoint and one Control Plane for every agent problem. AI agent sandboxes covers cloud agent runs and the sandboxes you host, the MCP gateway covers per-tool access to remote MCP servers, and shadow AI detection covers the servers and skills nobody approved. The secure web gateway for AI agents applies egress rules to any agent. The Control Plane holds the rules, policies and logs for all of them, and for the Connector in front of your databases.

Formal Endpoint on laptops

Transparent Mode on macOS and Linux; roll it out to Macs with your MDM. Existing clients keep working without a base URL change (docs).

Formal Endpoint in cloud agents

The headless Debian package runs in Cursor Cloud Agent and Devin environments and signs in with the platform’s short-lived OIDC token (guide).

Formal Endpoint in pods and tasks

A native sidecar in Kubernetes Pods, injected by label with the Helm chart, and a sidecar container in Amazon ECS tasks (docs).

Your identity provider

People sign in with SSO, and SCIM keeps users and groups in sync. Policies use the groups you already manage.

Logs in your SIEM

Log integrations forward Formal logs to AWS S3, Google Cloud Storage, Azure Blob Storage, Datadog, Splunk or Panther.

Policy and configuration as code

Policies are written in Rego. Manage Formal with Terraform, Pulumi or the Kubernetes Operator.

Audited controls

Formal holds SOC 2 Type II and ISO/IEC 27001. The reports are on security.formal.ai.

Cloud agents in production

Technologies secured
10+
Resources secured
1,000+
Logs per week
40M+
Sessions per week
600K+
“We've limited the amount of data that those cloud agents can access and we're able to tie that back to the specific user who is using that cloud agent, which is a feature that I'm only aware of Formal having.”
Roy Xu
Roy Xu
Software Engineer, Security, Cursor
Read the Cursor story ›

FAQ

Questions about AI coding agent security

Buying and fit

Are AI coding agents a security risk?

Yes, more than the autocomplete tools that AI coding assistant security used to be about. A coding agent runs with its engineer’s shell, tokens and network, and a prompt injection in a README, a code comment or a tool result can steer it. What it can break is bounded by that access, so start from least privilege: ask which of those permissions the agent’s task actually needs, and remove the rest from its reach.

How do you secure an AI coding agent?

Take long-lived secrets out of its environment, limit the hosts and actions it can reach, keep a person in the loop for pushes and merges, and log each request under a name. An AI coding agent security platform should do this outside the agent’s own settings; what to ask a vendor lists the checks.

What is the safest way to deploy AI coding agents?

In a disposable VM or container whose egress you control, signed in with a short-lived identity instead of a stored key, with interception that fails closed. Formal’s cloud agent guide sets up Cursor and Devin environments exactly like this. On a laptop, keep the agent’s sandbox on and add network rules for what the sandbox can’t see, such as which repository a push targets.

Is AI coding agent security the same as scanning AI-generated code?

No, and the timing shows why. A pre-commit secret scanner catches the key an agent committed; it never sees the key the agent sent to an API an hour earlier from .env. AI coding agent security solutions act during the run, on the hosts, credentials and git operations involved. When you compare them, ask which of the two each one covers. Formal is the runtime side only.

AI agents

Which coding agents does Formal recognize?

The agents in the known agent identities table, including Claude Code, Codex, Cursor, Devin, GitHub Copilot CLI and Windsurf. macOS matches their signing identity, Linux their process names. A tool that isn’t in the table matches no agent rule. You can still write a rule on its own signing identifier, as the Stripe guide does for curl.

How do you enforce one security policy across several AI coding agents?

Write the rule on what the agents have in common. process.has_agent_ancestor is true for every agent in the known agent table and for the processes it starts, so one network rule and one Rego policy cover Claude Code, Codex and Cursor on the same laptop. Narrow a rule with a per-agent flag such as process.is_claude_cli only where one tool needs different treatment. The rules and policies live in Formal’s Control Plane, so editing an agent’s settings.json leaves them as they were.

What does a coding agent see when Formal blocks a request?

The request fails with Formal’s message in place of the upstream response, naming the policy and carrying session and request IDs you can search in Logs; a blocked GitHub merge comes back as HTTP 403. Give each policy a reason, as the merge policy does with “Cloud agents cannot merge pull requests”, so the agent can tell its engineer why it stopped.

Put coding agent controls on the network path

Rules per agent process, keys held at the proxy and every request logged under an engineer, on laptops and in cloud agents.