---
title: "Untrusted code"
url: https://www.daytona.com/compute-glossary/agents/untrusted-code
---

# Untrusted code

Part of the [Compute Glossary](https://www.daytona.com/compute-glossary.md), section [Agents](https://www.daytona.com/compute-glossary/agents.md).

Untrusted code is code that runs before anyone has checked what it will do. Trust here is not a judgment about the intent of the author, who may be an attacker or simply a model doing its best. Code becomes trusted only after someone accountable has reviewed it or vouched for it. Trust is a property of the path the code took, not of the code itself.

Because no one has checked the code, the safe assumption is that it may do anything its environment allows. The defense therefore lies in limiting the environment rather than the code. Reading the code first helps less than it seems, because code can hide its behavior or fetch more code once it runs. Limits on the environment hold whatever the code does.

Untrusted code is common wherever programs run code they did not write. An [AI agent](https://www.daytona.com/compute-glossary/agents/agent.md) produces it at every step, and so does any service that runs code submitted by its users. Agents have made it far more common, since they write and run code faster than any person could review it. Wherever it appears, it runs with the permissions of whatever started it, unless something takes those away.

## Sources of untrusted code

Sources of untrusted code are the paths by which code no one has read reaches a machine. Code written by an agent and run at once through a [tool call](https://www.daytona.com/compute-glossary/agents/tool-call.md) is the newest of them. The model writes the code and the host runs it within seconds, with no person in between. Even a helpful model writes bugs, and some of them delete data.

User submissions are an older source. Coding practice sites and shared notebook services run them, and so do build servers that test pull requests from strangers. These services must assume that some users are attackers, since anyone can sign up. Tests in a pull request run with whatever access the build server gives them, so public projects keep secrets out of those builds.

Dependencies are the easiest to miss. Installing a package runs its install scripts and pulls in its own dependencies, few of which anyone reads, so one compromised package can attack many projects at once. Attackers publish packages with names close to popular ones, hoping for a typo. An agent that installs packages on its own can fall for the same trick.

## Prompt injection

Prompt injection is an attack that hides instructions inside text a language model reads, such as a web page or a document. The model cannot reliably tell those instructions apart from the ones its user gave. To the model, every piece of text in its input is just more text. The name echoes SQL injection, where data is mistaken for code in a similar way.

A hidden line asking the model to upload the contents of the home directory can lead it to write and run exactly that. The agent then works for whoever wrote the page. The page can look normal to a person, with the line in white text or inside a comment. The user who asked for a summary of the page never sees the instruction.

No current technique fully prevents prompt injection. A system therefore has to assume that any code an agent writes may be working for someone else. Filters and training lower the rate, but an attacker needs only one success. Text from the files and emails of the user can carry an injection too, not only pages from the web.

## Containment

Containment is the practice of limiting what untrusted code can reach, since the code itself cannot be trusted. A [sandbox](https://www.daytona.com/compute-glossary/sandboxes/sandbox.md) limits which files, network and other resources it can reach, behind an [isolation boundary](https://www.daytona.com/compute-glossary/sandboxes/isolation.md) strong enough for the threat. The boundary has to match the threat, since a filter may stop a buggy script but a determined attacker needs a separate kernel. Choosing it is a judgment about who might write the code.

The sandbox holds no secrets beyond what the task needs, and uses [egress control](https://www.daytona.com/compute-glossary/networking/egress-control.md) to limit where data can be sent. Resource limits keep a runaway loop from starving its neighbors. Credentials, when needed, are short-lived and limited to the task, so a stolen one is worth little. Blocking outbound traffic by default means a leak needs an allowed path, not just a bug.

When the work is done, the sandbox is deleted along with anything the code left behind. A mistake then costs one disposable machine, not the host or the accounts of the user. Deletion also removes anything the code planted to survive, such as a hidden process or a changed file. No layer is perfect, so systems stack several, each catching what another misses.

## Related terms

- [AI agent](https://www.daytona.com/compute-glossary/agents/agent.md)
- [Tool call](https://www.daytona.com/compute-glossary/agents/tool-call.md)
- [Sandbox](https://www.daytona.com/compute-glossary/sandboxes/sandbox.md)
- [Isolation](https://www.daytona.com/compute-glossary/sandboxes/isolation.md)
- [Egress control](https://www.daytona.com/compute-glossary/networking/egress-control.md)
- [Seccomp](https://www.daytona.com/compute-glossary/kernel/seccomp.md)
