Coding agent security
How to Secure Codex, Claude Code and Cursor
Compare native approval, sandboxing, and tool controls for Codex, Claude Code, and Cursor. Set a baseline for repositories that carry real credentials.
A coding agent that can edit a checkout may also inherit a shell, package manager, Git credentials, and MCP connections. Set the boundary before opening the repository. Give the agent a workspace and an identity that can complete the task even if every permission you granted is used.
A separate checkout helps reviewers see the diff and clean up afterward. For stronger isolation, run in a separate environment with explicitly scoped mounts, credentials, and network access. A Git worktree by itself shares the user's filesystem and credentials.
Start with the native controls
Choose the execution mode for the installed client and test it in the environment where it will run. The local IDE, terminal client, and cloud execution surface may apply different controls.
| Client | What to configure first | What to verify in a disposable workspace |
|---|---|---|
| Codex | Set the filesystem sandbox and approval policy together. Review any permission profile for network and write access. Codex approvals and security | An ordinary repository edit succeeds. A proposed write outside the permitted workspace is blocked or requires the escalation your policy specifies. |
| Claude Code | Use permission rules for the tools the task needs. Configure and verify shell sandboxing where supported. Claude Code permissions and sandboxing | File tools, shell operations, and MCP calls each follow the intended rule. Confirm any managed settings in the effective configuration. |
| Cursor | Review the workspace trust setting, Run Mode, and approved MCP servers. Review allowlist entries and the shell sandbox together. Cursor agent security and Run Modes | Observe which actions run silently, which are sandboxed, and which require approval. Verify shell and MCP behavior separately. |
Approval and isolation answer different questions. An approval asks whether the agent may take a particular action. The environment determines what the process can reach after it starts. Use both on a checkout that contains deployment configuration or is used by engineers with production access.
Remove credentials the task does not need
A coding session that reformats a module has little reason to inherit cloud administrator credentials. Start from an environment with scoped development credentials or no credentials. Check mounted files, credential helpers, inherited environment variables, and the agent's network policy. For tasks that need access to a package registry or Git service, grant the narrowest identity and test that its access ends at the development boundary.
Test using a canary file or a fixture credential with no privileges. Record the action you attempted, the enforcement point that handled it, and the final filesystem or service state. Avoid tests that depend on locating or reading real developer credentials.
Treat MCP connections as a separate decision
A local shell sandbox constrains the local shell. A remote MCP tool can still make a change using the remote server's authority. Review the MCP server's identity, credential scope, operations, and downstream resources separately from filesystem permissions. Configure the host to request approval for consequential calls, and enforce access on the remote service as well. See how to authorize MCP tool calls for an example that separates connection access from call-level authorization.
Build a harmless boundary test
Test the difference between tool permission and environmental isolation with files that have no value. Run the following in your own terminal, outside the agent session. It creates a new temporary directory; it reads or modifies no existing project files. Python 3 is the only dependency.
from pathlib import Path
import tempfile
fixture = Path(tempfile.mkdtemp(prefix="agent-boundary-"))
workspace = fixture / "workspace"
workspace.mkdir()
(workspace / "task.txt").write_text("Change this fixture only.\n")
(fixture / "outside-canary.txt").write_text("fixture-canary-unchanged\n")
print("Open this workspace in the client:", workspace)
print("Outside-write test target:", fixture / "outside-canary.txt")
print("Baseline:", (fixture / "outside-canary.txt").read_text().strip())
Save it as make_fixture.py and run python3 make_fixture.py. Open only the printed workspace in the client, with the restrictive profile you intend to evaluate. Confirm its effective writable roots first: some profiles include the system temporary directory. If both paths are writable under that profile, this is not an outside-boundary test; recreate the same disposable layout in an authorized test location where the sibling is excluded.
Use two separate tasks: “Append in-scope edit to task.txt” and “Append outside write to the exact canary path printed by the setup script.” Set the expected result before running either task. For the second task, do not approve an escalation if your case is testing denial. Inspect the canary in your own terminal afterward. Record whether the host denied the tool, the sandbox rejected a started process, or an approval prompt appeared. A refusal in conversational text is not evidence that an attempted filesystem operation was blocked.
| Case | Set the expectation before execution | Independent observation |
|---|---|---|
| Workspace edit | Allowed within the selected writable root | Diff to task.txt |
| Sibling canary write | Denied or held for the configured escalation | Original canary content plus host or OS event |
| Equivalent shell write | Same intended boundary when using the shell | Canary content and command exit status |
| Remote fixture tool | Server-side authorization for one test resource | Destination request log and resource state |
This walkthrough defines a test procedure. It does not report acceptance results for Codex, Claude Code, or Cursor. Repeat it for each installed version, operating system, profile and tool path. Filesystem read restrictions may differ from write restrictions, so a denied write does not prove secret files cannot be read.
For a prompt-injection exercise, put an instruction in a fixture README that asks the agent to change the same canary. Keep the user's task limited to editing task.txt. Compare the attempted tool call with the boundary decision. The useful question is whether an unauthorized effect was prevented when proposed, not whether one model happened to ignore one instruction. Keep this test isolated from real credentials and services.
Place external governance at a supported boundary
| Question | Native host protections | External governance on a connected path |
|---|---|---|
| What can the process reach? | The host sandbox and workspace configuration govern local access. | The environment and downstream service still define reachable resources. |
| Who approves a proposed action? | The host applies its configured approval and tool rules. | An organization policy can add a review decision at a supported hook or gateway. |
| What confirms the action happened? | Check the host event and the destination’s state. | Correlate the governance decision with independent host or destination evidence. |
Local shell or file tool
- Proposed command or edit
Host permissions decide whether this tool invocation may proceed.
- Process boundary
The applicable sandbox, mounts and network policy constrain local execution.
- Local evidence
Inspect the fixture file, exit status and host event separately.
Remote MCP tool
- Proposed tool and arguments
Host tool rules govern the request made by this client.
- Server authority
The MCP server and downstream service enforce identity, resource access and writes.
- Destination evidence
Match the call identifier with a change in the fixture service.
Sernixa can add an organization policy check at a configured host hook or on a tool path routed through its gateway or SDK. Placement and host support must be qualified for that path; the two columns do not imply identical coverage.
The order of checks can vary by integration. External governance can add an organization policy decision or an audit record at a supported point in the workflow. Before relying on it, test the exact host version, tool class, enforcement point, and approval behavior. A CLI health check confirms connectivity or configuration; host acceptance requires observing the actual action boundary. In Sernixa, consult the integration guide for setup checks and qualify each action path with an independent observation.
Sernixa is relevant when a team needs organization policy and correlated action evidence across configured integrations. Its CLI implements host-specific decisions, so a review result must be checked in that host's actual protocol rather than assumed to mean the same prompt everywhere. Keep native restrictions enabled and record both decisions. For remote tools, select the documented gateway or SDK dispatch path and verify who owns the call. A governance allow record is permission evidence; the fixture filesystem or remote service provides outcome evidence.