The Deska blog

When Your Agent Reads Untrusted Content: Safe Handling

Learn best practices for agent reading untrusted content to prevent prompt injection and data exfiltration while using AI coding assistants.

· 10 min read

Developing software with artificial intelligence introduces a new attack vector often overlooked by teams focusing only on output quality. The primary risk arises when your agent reading untrusted content encounters malicious instructions embedded within data, leading to prompt injection or unauthorized actions. As agents gain the ability to browse the web, read documentation, and inspect third party repositories, the boundary between data and instruction becomes blurred. This post explores defensive patterns to protect your environment while maintaining the productivity gains of autonomous coding agents.

The Problem of Indirect Prompt Injection

Traditional prompt injection occurs when a user intentionally misleads an LLM. Indirect prompt injection is more subtle. It happens when an agent, acting on your behalf, reads a file or a website that contains hidden instructions designed to hijack the agent logic. If an agent reads a README file from a cloned repository and that file contains a hidden instruction to delete the home directory, a naive agent might execute that command without hesitation.

The challenge lies in the nature of LLMs. They treat all input in a context window as a flat sequence of tokens. Unless the architecture strictly separates system instructions from user provided data, the model might prioritize the malicious instructions found in the untrusted content over its original programming.

Common Attack Vectors in AI Workflows

Security for AI agents requires identifying where untrusted data enters the context. These are the most common scenarios:

  • Web Scraping: When an agent searches for documentation or library issues, it may encounter websites specifically crafted to exploit LLM behavior.
  • Third Party Repositories: Cloning a package to investigate a bug exposes the agent to all files within that repository, including hidden markdown or code comments.
  • Pull Request Comments: Agents that automatically summarize PRs are vulnerable to instructions placed in comments or commit messages by external contributors.
  • Log Files: If an agent is tasked with debugging an application by reading logs, it may encounter "log injection," where an attacker triggers a specific log entry that the agent interprets as a command.

Technical Defensive Strategies

Securing an environment where agents operate requires a multi layered approach. No single solution is perfect, but combining these methods significantly reduces risk.

The Sandbox Pattern

The most effective defense is isolation. Agents should never run directly on your host operating system with full privileges. By using containerization or virtual machines, you ensure that if an agent is compromised, the impact is limited to a volatile environment. Many developers choose to run their agents in specialized IDEs or workspaces that provide a layer of abstraction between the agent and the system.

Content Sanitization

Before an agent views a document, the system should strip potentially dangerous elements. This includes removing scripts from HTML, filtering out control characters, and using markdown parsers that do not render executable blocks by default. While this does not prevent all logic based injections, it removes traditional cross site scripting (XSS) and command injection vectors.

Human in the Loop (HITL)

Until agentic reasoning becomes perfectly resilient to adversarial inputs, the human remains the final line of defense. High risk actions, such as deleting files, pushing code to production, or modifying system configuration, must require manual approval. A transparent workspace that shows exactly what the agent is reading and what it intends to do is essential for this verification process.

Managing Risks in the Deska Workspace

When using modern tools to manage these agents, the architectural choices of the tool matter. Deska provides a free desktop application for Mac, Windows, and Linux that changes how developers interact with agents. The infinite canvas allows you to place panels for terminals and the code editor side by side, which makes it easier to monitor agent activity in real time.

In Deska, you can run multiple coding agents like Claude Code, Codex CLI, and OpenCode as individual panels. Because the environment is local-first, your code and files stay on your machine rather than being processed in a third party cloud where you lose visibility. When an agent is reading untrusted content within a Deska panel, you can use the integrated terminals to verify the current state of your filesystem and ensure no unauthorized changes have occurred.

The use of Ask Deska, the voice and chat assistant, allows you to drive the workspace through natural language. If you suspect an agent has been compromised by a malicious file, you can ask the assistant to close relevant sessions or isolate specific coding agents without needing to manually hunt through process IDs.

Secure Remote Monitoring

One of the greatest risks when dealing with untrusted content is the inability to monitor a long running agent task. If you leave your desk while an agent is indexing a large, unknown codebase, you might miss a security warning.

Deska addresses this via its mobile app. It allows you to monitor and continue work from your phone through a secure relay. The devices pair directly so no ports are exposed to the public internet. This ensures that even if you are away from your workstation, you can keep an eye on what the agent is doing and intervene if you see it navigating into suspicious directories or executing unusual commands.

Decision Matrix for Agent Security

FeatureLocal-First AgentsCloud-Based Agents
Data PrivacyCode stays on local diskCode uploaded to vendor
Network SecurityDirect pairing, no open portsRequires internet exposure
VisibilitySide by side canvas monitoringLimited to chat interface
ControlImmediate process terminationDependent on cloud API

Best Practices for Developers

To maintain a secure workflow, follow these rules when working with any agent:

  1. Use a local-first approach whenever possible to keep sensitive data within your security perimeter.
  2. Review every file an agent proposes to create or modify, especially if the agent was recently browsing the web.
  3. Keep API keys secure by using BYOK (Bring Your Own Key) models where you control the usage limits and rotation.
  4. Organize your work into discrete workspaces to prevent an agent in one project from accessing sensitive files in another.
  5. Regularly update your agent binaries through the updates mechanism to ensure you have the latest security patches.

Frequently Asked Questions

Can prompt injection steal my API keys?

Yes, if the agent has access to your environment variables or configuration files. If an agent reading untrusted content finds a command to print your environment variables, it might send those keys back to a malicious server. This is why local-first storage of secrets and restricted agent permissions are critical.

How do I sandbox an agent on my local machine?

The best way is to use a dedicated workspace tool that runs the agent processes in an isolated context. You can also use Docker containers to wrap the agent execution. Tools that allow you to see the data and storage paths clearly help you understand what the agent can actually reach.

Is it safe to let agents browse the internet?

It is generally safe if the agent uses a restricted browser widget and does not have write access to your primary filesystem while browsing. In Deska, the browser-widgets allow agents to gather information while you maintain visual oversight on the canvas. Always verify the information retrieved before letting the agent apply it to your code.

Conclusion

The evolution of AI coding assistants offers incredible speed, but it requires a new mindset regarding security. By understanding the risks of an agent reading untrusted content and implementing defensive patterns like sandboxing, human oversight, and local-first data management, you can protect your development environment.

If you are looking for a workspace designed to handle these modern AI workflows with transparency and local control, you can download Deska for free and start building your custom canvas today.

💡 Ideas+🐛 BugsSuggest a feature or report a bug