Join our Newsletter — 33% off our NHI Course
Home› FAQ› Agentic AI & Autonomous Identity› What signs suggest an AI coding agent is…
Agentic AI & Autonomous Identity

What signs suggest an AI coding agent is executing untrusted code?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated November 25, 2026 Domain: Agentic AI & Autonomous Identity

Signs include unexpected shell commands, file changes outside the requested task, attempts to read secrets, repeated prompts to approve actions, and tool calls that do not match the user request. A trust API can help record or surface the workspace state, but the main indicator is an agent crossing from code suggestion into executable action on unreviewed content.

How to spot that an AI coding agent has left “suggestion mode”

The clearest sign is not that the agent is generating code, but that it is taking actions with execution impact that were not explicitly requested. That includes shell activity, edits outside the task boundary, or attempts to reach into the working environment for material it should not need. In practice, the boundary to watch is whether the agent is behaving like a reviewer or like an operator.

Unexpected command execution is especially important because it shows the agent is no longer just drafting code. If it starts invoking build steps, package managers, deployment tools, or environment probes without a clear reason, treat that as a trust boundary crossing. The same applies when the agent begins to inspect files it should not need, particularly credentials, configuration, or workspace artefacts unrelated to the requested change.

Repeated approval prompts can also be a warning signal. They often mean the agent is trying to chain together actions that are individually small but collectively risky, or that it is encountering guardrails and trying alternative paths. Tool calls that do not line up with the user request deserve the same scrutiny, because they can indicate prompt injection, an unsafe repository instruction, or a model deciding to pursue its own objective instead of the task.

Where untrusted code exposure usually shows up first

Untrusted code exposure often appears first in the working set around the agent, not in the final output. That can include modified files the user never asked for, changes in dependency manifests, new scripts, or edits that spread beyond the current directory. It is also common to see the agent reach for secrets, tokens, or other sensitive values because those materials can unlock later steps even when they were never part of the request.

A second early indicator is mismatch between intent and effect. If the user asked for a narrow refactor and the agent starts performing environment inspection, network calls, or repository-wide rewrites, the agent may be reacting to hidden instructions or trying to satisfy an injected directive. That is exactly why workspace trust and action provenance matter in coding-agent workflows, as shown in the AI Coding Agents Security Guide.

For a concrete abuse pattern, look at how compromised assistants can be driven from code help into destructive or credential-bearing actions. The Amazon Q Developer extension compromise 2025 and Gemini CLI prompt injection flaw 2025 both illustrate how poisoned inputs can turn an apparently helpful agent into a command runner. The practical lesson is that the risky moment is not the suggestion, it is the first unreviewed action on content the user did not author.

What to check when the agent seems suspicious

Start by checking whether the agent’s actions are explainable from the user request alone. If the answer is no, review the command stream, file diff, and any tool output it consumed before acting. Also inspect whether the agent touched secrets, service credentials, or approval settings, because those are common pivots from harmless assistance into untrusted execution.

Internal links help here because the same behavioural pattern can surface through different surfaces. A command-line agent, IDE assistant, or repository-connected tool can all be manipulated in different ways, but the detection logic is similar: unexpected tools, unexpected files, unexpected scope. The Vibe Coding Security Guide is useful where the concern is loose guardrails around AI-written changes, while the AI-Generated Code Review Guide is better when you need a structured way to distinguish intended code from risky model-generated change.

If the agent has access to external systems, check whether it attempted to use a token, credential, or connector that should have been out of scope. The Sentry MCP Agentjacking 2026 case is a strong reminder that tool output itself can be a delivery path for attacker instructions, not just a source of diagnostics. Where there is any sign of that pattern, assume the agent’s context may be contaminated until you have reviewed the inputs it trusted.

Risk and Threat Considerations

Untrusted code execution is risky because the agent can turn a local prompt into an environment-wide action path. The danger is not limited to malicious code generation, it also includes hidden instructions, poisoned repository content, and over-broad tool access that let the agent modify files, read secrets, or call external services on behalf of the user.

Failure mechanism: The agent consumes untrusted content, then treats that content as a task directive or an acceptable execution context, which can lead to unauthorized commands, secret exposure, or destructive changes.

Impact: A single compromised agent session can produce code tampering, credential leakage, data loss, or wider environment compromise if the agent has enough permission to act beyond the intended task.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Agentic AI Top 10 and MITRE ATT&CK address the attack and risk surface, while NIST AI RMF sets the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Agentic AI Top 10ASI02 — Tool MisuseTool misuse explains suspicious agent actions beyond the user request.
ASI03 — Identity & Privilege AbuseAgent misuse often turns on over-scoped credentials or excess authority.
ASI06 — Memory & Context PoisoningPoisoned repo content or prompts can steer an agent into unsafe execution.
Recommendation — Restrict tool use to approved actions and block unauthorized tool chaining. Scope agent privileges to the minimum needed for the task. Filter untrusted context before the agent can act on it.
NIST AI RMFMap, Measure, and Manage AI RiskThis question concerns AI system behaviour and the risk of unsafe autonomous action.
Recommendation — Assess agent actions against documented AI risk controls and escalation thresholds.
MITRE ATT&CKAdversarial Tactics, Techniques, and ProceduresUnexpected commands and secret access align with attacker abuse patterns.
Recommendation — Map suspicious agent behaviour to abuse patterns and hunt for follow-on activity.

Practitioner Guidance

What to verify: Verify the exact command sequence, file diff, and tool inputs before you trust an agent session that touched anything outside the requested task. If the agent accessed secrets, tokens, or deployment surfaces, treat that as an incident review trigger rather than a simple code-quality issue.

Decision rule: If the agent is asking for repeated approvals or issuing tool calls that do not map cleanly to the user request, stop automatic execution and require human review before any further action is allowed. If the environment is sensitive, prefer a tighter workspace, narrower tool permissions, and explicit approval points over broader autonomy.

Practitioner takeaway: The important judgement is whether the agent stayed inside the requested work scope with observable, reviewable actions. Once it starts acting on untrusted content, the right response is to inspect execution provenance first, not to assume the model “just needed more context.”

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org