Untrusted Code is code whose origin, integrity or intent has not been verified, such as third-party packages, downloaded scripts, user-supplied plugins or pull requests from outside contributors. Running it with the host's privileges can lead to credential theft or compromise. Defenders isolate execution in sandboxes, pin and verify dependencies, restrict network and secret access, and review before merging.
What Untrusted Code Means in Practice
Untrusted code is not just “unknown” code, it is code that has not earned trust through provenance, integrity, or review. The security problem is that code can execute with privileges the host already has, so the risk is not limited to the code itself, but extends to the environment, data, credentials, and network paths available at runtime.
This is why defenders treat untrusted code as a boundary-crossing problem rather than a simple software-quality issue. A script, package, plugin, or contributor patch can be technically functional and still be unsafe to execute until it has been checked, constrained, and observed in a controlled environment.
Where Untrusted Code Comes From
In practice, untrusted code often arrives through supply-chain paths that developers and operators rely on every day: downloaded installers, package registries, build scripts, browser extensions, automation hooks, CI jobs, and third-party integrations. The same concern applies to code that is internally submitted but not yet reviewed, because origin alone does not prove safety.
The core issue is that trust is easy to assume and hard to verify at speed. A dependency may be popular, a pull request may look routine, or a plugin may be introduced as a convenience, yet any of these can carry unexpected behavior, hidden side effects, or malicious logic that only appears once it is executed in a real environment.
For developer-facing environments, this is why isolation and review are part of the security model, not optional hardening. NHIMG’s Web3 Developer Operational Security Guide is one example of how practitioners can think about isolating risky execution and reducing exposure when untrusted code lands in a workflow.
Why Running It With Real Privileges Is Dangerous
The danger comes from what the code can reach once it is executed. If it inherits the host’s user context, it may read secrets, access caches, call internal services, alter files, exfiltrate data, or trigger privileged workflows. In modern environments, that can include cloud credentials, API tokens, session material, build-system trust, or deployment permissions.
Untrusted code is especially risky when the execution environment has broad network reach or direct access to sensitive inputs. The difference between “it ran” and “it compromised us” is often just whether the code could see secrets, talk outbound, or chain into another trusted system before defenders noticed.
The same principle also matters in container and cluster environments, where a workload may look isolated but still be able to reach metadata services, mounted secrets, service endpoints, or other shared resources if controls are incomplete. NHIMG’s GKE Security Hardening Guide is a useful reference for the broader hardening pattern that limits what risky workloads can do if they are ever executed.
How Defenders Contain and Validate It
The usual defensive pattern is to assume the code is unsafe until proven otherwise. That means running it in a sandbox or other constrained environment, restricting outbound connectivity, separating it from high-value secrets, and verifying dependencies before execution or merge. The goal is not to “trust less” in the abstract, but to make sure untrusted code cannot directly inherit the most sensitive parts of the host.
Review and verification should happen before the code is allowed to influence production systems. For dependency-heavy ecosystems, pinning versions, checking integrity where possible, and controlling what can be installed or executed are practical ways to reduce the chance that a malicious or altered package is accepted as normal. The same logic applies to pull requests from outside contributors: code review is not a ceremonial step, it is a trust decision.
Controls from broader security guidance still apply here because the problem is fundamentally one of execution control, privilege, and integrity. The NIST SP 800-53 Rev 5 Security and Privacy Controls catalog is a strong baseline for thinking about access control, authentication, configuration, logging, and system integrity around untrusted execution.
What to Watch For After Exposure
If untrusted code has already run, the main question becomes what it touched before controls cut it off. That includes secrets in environment variables, cached credentials, developer tokens, SSH keys, signing material, source code, and internal network paths. Even a short execution window can be enough for credential theft or for planting persistence in a build or deployment workflow.
Post-execution review should therefore look beyond the code artifact itself and examine the surrounding systems for signs of misuse: unusual outbound requests, new files, unexpected process launches, altered build outputs, or changes to trusted dependencies. When the code path sits inside a CI/CD or developer workstation workflow, review should also consider whether any tokens, sessions, or signed artifacts need to be revoked and reissued.
Where untrusted code is part of a broader adversary path, threat-mapping becomes useful because code execution often serves as the foothold for credential access, lateral movement, or privilege escalation. The MITRE ATT&CK Enterprise Matrix provides a useful vocabulary for tracing what an attacker may do after the first malicious execution succeeds.
Risk and Threat Considerations
Untrusted code is dangerous because it converts ordinary software execution into a potential compromise path. The risk is highest when the code can inherit local authority, reach secrets, or talk to internal services, because that makes a single execution event enough to become a credential theft or supply-chain compromise opportunity.
Failure mechanism: A malicious or altered script, package, or plugin runs inside a trusted environment and abuses the host’s permissions, network reach, or secret access before defenders detect it.
Impact: The result can be data exposure, secret theft, unauthorized actions, tampered builds, persistence in the delivery pipeline, or broader compromise of systems that trusted the same execution context.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | AC-6 — Least Privilege | Limits what untrusted code can access if it executes. |
| SC-39 — Process Isolation | Separates risky code from the host and other workloads. | |
| SI-7 — Software, Firmware, and Information Integrity | Supports verifying that code and dependencies are authentic and intact. | |
| Recommendation — Constrain execution to the minimum privileges needed for the task. Run untrusted code in isolated environments that reduce host exposure. Verify code integrity before execution or deployment. | ||
| CIS Controls v8 | CIS-2 — Inventory and Control of Software Assets | Helps track third-party code and packages entering the environment. |
| Recommendation — Maintain an accurate inventory of software and dependencies. | ||
| MITRE ATT&CK | T1203 — Exploitation for Client Execution | Covers code that executes to gain initial foothold or run malicious actions. |
| Recommendation — Map suspicious code execution to client-execution techniques and investigate the launch path. | ||
Practitioner Guidance
Why practitioners should care: Treat untrusted code as an execution-risk decision, not just a code-quality issue. The practical question is always what the code can reach if it runs, especially secrets, network paths, and privileged workflows.
Common misunderstanding: Many teams focus on whether the code “came from a known source” and miss the more important question of whether it has been verified and constrained before execution. Origin alone does not make code safe.
Practitioner takeaway: The safest default is to isolate first, verify second, and only then allow the code to touch sensitive resources or trusted deployment paths.
Related resources from NHI Mgmt Group
- What breaks when a workflow engine can execute untrusted code inside the same environment that stores secrets?
- What breaks when CI/CD workflows can run untrusted code with privileged tokens?
- What breaks when local MCP configuration can be rewritten by untrusted code?
- What breaks when AI code review tools are allowed to analyse untrusted pull requests?
Deepen Your Knowledge
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.
Reviewed and updated by the NHIMG editorial team on November 26, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org