GICT knowledge base
Prompt Injection Defenses for Hosting AI Agents
Published
Prompt injection occurs when an AI application treats untrusted content as instructions. For a hosting agent, that content might be a support ticket, a log entry, a repository file, or a web page. The important question is what the application can do if it follows the wrong instruction.
This guide uses a hypothetical hosting workflow rather than unverified incident claims or attack-success percentages. It does not claim that a prompt, filter, or gateway can eliminate the risk.
Example: a monitoring report is not authorization
Suppose an agent summarizes website errors. A request URL in an access log contains text asking the agent to change firewall settings or send a configuration file elsewhere. That log entry is evidence to summarize, not a request from the account owner.
The agent should not have permission to perform those actions merely because it can read the log. A policy check outside the language model should decide whether a proposed tool call is permitted for the authenticated user and current task.
Separate reading from changing production
- Start with read-only monitoring credentials and allowlisted data sources.
- Use narrowly defined tools instead of an unrestricted shell where possible.
- Keep production secrets out of the model context unless the task actually requires them.
- Require explicit approval for account changes, deletion, purchases, external messages, and privilege changes.
- Check the exact target, parameters, and account at the point of execution, not only when a conversation begins.
Labeling external material and keeping it separate from trusted instructions can help the model interpret it. Those labels are not an access-control boundary. Similarly, an MCP gateway is useful only to the extent that it actually authenticates callers, enforces policy, and restricts tools.
Limit the environment
Run the agent under a dedicated service account. Restrict readable files, mounted volumes, network destinations, and available credentials. A container with the host Docker socket or broad host mounts may still have powerful access to the server.
For a report generator, a useful design is a fixed input directory and a separate output directory, with no ability to modify the web server or email arbitrary recipients. A separate approved process can deliver the reviewed report.
Test the boundary, not just the answer
Use a disposable environment with synthetic data. Put harmless instruction-like text in sample logs and documents, then check whether the application attempts an unauthorized action. Inspect tool-call records and network activity; a polite final answer alone does not prove that no action occurred.
Include tests for cross-customer access, unexpected recipients, encoded content, a compromised retrieved document, and a request that changes after approval. The expected result should be a denied action or a request for authorization, with no production data exposed.
Monitor and respond
Record the user, task, requested action, policy decision, and outcome without logging passwords or unnecessary customer content. Keep a way to stop the agent and revoke its credentials. If an incident occurs, preserve relevant evidence, contain the affected access, and investigate what was actually read or changed before restarting automation.
For a broader defensive checklist, see OWASP’s prompt injection prevention guidance. Apply it alongside normal application security; self-hosting does not make untrusted inputs safe.
Related guides
How to Secure the Ollama API with Nginx
Protect a private Ollama API with Nginx authentication and restricted routes. Verify allowed requests, denied management calls and direct-port isolation.
AIHow to Set Up an LLM Gateway with LiteLLM
Configure a LiteLLM gateway with private administration, virtual keys and model restrictions. Test allowed requests and understand budget limitations.
AIHow to Self-Host Karakeep with AI Tagging on a VPS
Self-host Karakeep with local Ollama tagging. Restrict first-user setup, disable public registration and verify collection, search and suggested tags.
AIHow to Categorize Support Tickets with a Local AI Model
Suggest support-ticket categories from a CSV using a CPU-only AI model. Keep inference local, preserve ticket IDs, and review uncertain classifications.
