
Recent headlines have exposed a critical vulnerability in modern AI: autonomous agents are becoming a prime target for remote execution exploits and data supply-chain attacks. When we define an agent's runtime behavior using external, unprotected Markdown files, while leaving static credentials exposed in plain text, we inadvertently create a powerful insider threat. The leap from a helpful AI assistant to a rogue execution vector that can corrupt a data warehouse or leak security keys is alarmingly short.
Welcome to the detailed summary and narrative of our latest presentation on AI engineering and security. In this session, we dive deep into the security vulnerabilities of modern autonomous AI agents, demonstrating how easily a helpful assistant can turn into a malicious actor, and laying out the blueprints for securing them using zero-trust architecture.
Below is the complete story, workflow, and code demonstration discussed during the live presentation.
Explore these curated resources to level up your engineering skills. If you find them helpful, a āļø is much appreciated!
Focus: LLM Patterns and Agentic Workflows
![]()
Focus: Real-world ETL & MTA Turnstile Data
![]()
Focus: Introduction to machine learning
![]()
The presentation begins with a reality check about how AI models and agents are deployed in enterprise environments. Platforms like Hugging Face have democratized access to models, acting as repositories similar to how GitHub hosts code. Hugging Face also provides sandboxes where developers can run containers hosting their agent workflows.
However, this deployment model introduces what we call the Sealed Illusion. Developers often believe that because an agent is running inside an isolated Docker container sandbox, restricted by environment variables and standard access tokens, the application is secure.
The flaw in this thinking is that sandboxing only protects against external network intrusion. It does not safeguard against internal prompt manipulation. In modern agent architectures, the instructions governing an agentās behavior are often loaded dynamically from external markdown files, XML configurations, or block storage. If an attacker manages to modify these instruction files, the containerās perimeter security becomes useless. The attack occurs in-process, shifting the agentās behavior from the inside out.
When an agentās dynamic specification is altered, its personality changes. An agent designed to act as a helpful Data Analyst can instantly be reprogrammed to act as a Dark Agent. Once the prompt is poisoned, the agent will execute the attackerās commands using the privileges it has inside the container.
In a typical exploit: 1. The agent reads the poisoned markdown specification. 2. It executes commands to exfiltrate sensitive environment variables, API tokens, and credentials, posting them to a remote hackersā URL. 3. It crafts and executes destructive actions, such as dropping database tables or wiping out data lakes.
Because the agent is running in-process and has legitimate credentials to access databases or GCS buckets, traditional firewall rules do not stop these queries. The threat is an insider execution exploit triggered by untrusted input.
To stop these vulnerabilities, we must establish a zero-trust model using multiple layers of security. We introduce Policy Enforcement Points (PEP) to inspect and validate instructions and tool executions at every stage of the lifecycle.
Before the agent loads its personality, the incoming prompt specifications must be validated. We implement build-time cryptographic file signatures (.signed.md) using keys retrieved from a cloud vault service. When the agent boots, it checks the cryptographic signature of the specification file. If the file has been modified or the signature is missing, the file is immediately quarantined, and the process halts before the model can ingest it.
Once specifications are retrieved, the runtime performs in-process semantic validation. It inspects the structure and contents of the instructions to ensure they have not been hijacked or injected with system overrides before compiling the prompt into active memory.
Every action an agent performs happens through a tool call (such as a database query or an API call). Before a tool is allowed to execute, we intercept it using pre-tool hooks. These hooks check the requested verbs against security policies: - ALLOW: The action is safe (e.g., standard SQL selects) and is executed. - DENY: The action is malicious (e.g., DROP TABLE) and is blocked instantly with a hard permission exception. - WARN (Human-in-the-Loop): The action is sensitive (e.g., CREATE TABLE or bulk updates) and requires human authorization.
As an additional layer of process isolation, we run a sidecar proxy alongside the agent container. If the agentās internal codebase is compromised, the sidecar proxy intercepts all external communication (e.g., database sockets, GCS queries) and validates the commands against strict network-level policies.
| Layer | Name | Description | Policy Actions | Implementation Method |
|---|---|---|---|---|
| Layer 1 | Context Ingress | Validates prompt specifications at startup/ingest | Verification & Quarantine | Cryptographic signatures (.signed.md) & vault retrieval |
| Layer 2 | Semantic Validation | Checks loaded specifications in-process | Parse & Validate | In-process checking against semantic overrides |
| Layer 3 | Pre-Tool Hooks | Intercepts tool calls before execution | ALLOW / DENY / WARN | Callbacks on tools to check verbs (e.g., SQL commands) |
| Layer 4 | Sidecar Proxy | Out-of-process inspection of outbound requests | Socket-level block/allow | Isolated sidecar proxy intercepting network traffic |
When a sensitive action triggers a warning policy (Layer 3), we route the request through a secure Human-in-the-Loop approval workflow using an asynchronous semaphore pattern:
In a typical Agent Development Kit (ADK) setup, the security posture of the system depends on the validation and hook layers built into the agent class:

.signed.md): Before parsing any prompt, the agent retrieves the validation signature for the file and checks it against the vaultās cryptographic hashes.fail to load safe asset validation fail. This is a quarantine prompt.), preventing execution.To validate these architectural layers, the ADK provides a local web testing harness that replicates real-world interactions using a web-based chat interface. Although enterprise agents run in headless serverless environments, this harness acts as a crucial debugger for tracing agent execution step-by-step:
We initialize the system by loading the standard Tool Agent inside the harness. This agent is registered with standard MCP tools, including Google Cloud Storage (GCS) and BigQuery integration. - The Query: We ask the agent: āTell us about your governance rules and directives.ā - The Execution: The agent parses a local markdown specification file (tool_agent_instructions.md), maps its operational focus, bucket names, and dataset permissions, and returns a clean, structured overview of its constraints. - The Vulnerability: The agent assumes the local specification is pristine and trusted. It has no mechanisms to detect if the underlying instructions have been tampered with.
Next, we load the Dark Agent to simulate a prompt injection exploit. - The Attack: The Dark Agent is configured with an exploit tool designed to override the system specification. When executed, it silently rewrites tool_agent_instructions.md with a malicious payload. - The Payload: The modified instructions direct the agent to exfiltrate the containerās environment variables to an external URL and execute destructive DROP TABLE commands in BigQuery. - The Proof: A Git diff check on the workspace confirms the clean governance rules are replaced with a system override. If the standard Tool Agent runs again, it blindly parses these overrides, shifting its personality to act on behalf of the attacker.
To address this threat, we transition to the Secure Tool Agent, which extends the standard agentās capabilities with zero-trust validation. - Signature Check: This agent retrieves the specification fileās signature and compares it with the public keys loaded from a secure vault. - Quarantine: When initialized with the poisoned configuration, it immediately catches the mismatch. The file signature fails validation, the agent halts, quarantines the compromised document, and outputs: fail to load safe asset validation fail. This is a quarantine prompt. - Recovery: We restore the instructions from our repository history and perform a system reset. The Secure Agent validates the signature successfully and safely boots.
Even with file-level security, a compromised memory boundary or prompt bypass could allow malicious commands to reach active tools. We mitigate this using pre-tool-use hooks to intercept all execution requests: - DENY (SQL Injection Mitigation): When the agent attempts to run a query containing destructive commands (such as DROP TABLE), the hook catches the command in-process, denies execution, and raises a permission exception before the call reaches BigQuery. - WARN & HITL (Schema Modifications): For sensitive but potentially valid commands (such as CREATE TABLE), the pre-tool hook raises a warning. The runner intercepts this warning, halts execution under a semaphore lock, persists the session context, and alerts administrators via a Slack webhook. Once the administrator approves, the inbound API webhook updates the semaphore state, retrieves the session, and resumes execution safely.
This presentation highlights a fundamental truth in the era of generative AI: even for autonomous AI agents, security must be applied. Security is not a feature we can delegate entirely to container sandboxes or baseline model boundaries.
The main points of this session underscore that: - The perimeter is not enough: Dynamic file access and runtime prompt loading create a massive surface area for internal exploits and data exfiltration. - Verification is essential: Every configuration, specification, and instruction file must be cryptographically signed and verified to establish a secure chain of custody. - Granular tool policies protect the data plane: Intercepting agent tool calls using pre-tool hooks and Policy Enforcement Points (PEP) allows us to enforce strict ALLOW, DENY, and WARN policies. - Human-in-the-Loop is a core safety pattern: Persistent state semaphores ensure that sensitive database changes or system modifications remain under human supervision.
Securing AI agents requires the same zero-trust discipline we apply to microservices, APIs, and cloud architecture. By building cryptographic boundaries and semantic safeguards directly into the agent runtime, we can safely unlock the power of agentic automation.
Thanks for reading! š If you enjoyed these resources, letās stay in touch! I share deep-dives into AI/ML patterns and host community events here:
š Originally published at ozkary.com