AI Agents in Production: Why Docker Isn't Enough (and How to Do It Right)
Deploying AI agents without proper isolation is a recipe for chaos in your pipelines. Here's what we learned about secure production rollouts with Docker and sandboxes.

An AI agent that generates SQL code on the fly. A nice promise of automation for your data pipelines. Except in production, this agent accidentally wiped a production table because it misinterpreted an instruction. The kind of scenario that turns an impressive demo into a major incident.
This situation is far from unusual. We're seeing more and more organizations integrating AI agents with Docker sandboxes for data pipelines, whether to generate dbt transformations, optimize Databricks queries, or orchestrate complex pipelines. The problem doesn't come from these agents' ability to produce functional code. It comes from letting them run in environments where a mistake can have irreversible consequences.
Containerization with Docker seems like an obvious solution. You isolate the agent, control its resources, clean up after execution. But Docker alone only solves part of the problem. What really matters is creating a true sandbox environment that limits not just system isolation, but also data access, network permissions, and execution capabilities. This approach is part of a broader transformation in the role of analytics engineers facing automation.
The real risks of unisolated AI agents
When you deploy an AI agent to automate data tasks, you typically give it access to three critical things: credentials, executable code, and data. That's exactly what it needs to do its job. It's also exactly what can go wrong.
Let's take a concrete example: an AI agent configured to generate dbt models from natural language descriptions. A user asks "create me a model that aggregates sales by region". The agent generates the SQL code, the YAML configuration file, and even suggests tests. Everything looks perfect in development.
In production, the same agent receives an ambiguous instruction. It generates code that references a sensitive table it shouldn't touch. Or worse, it creates an infinite loop of transformations that saturates your Databricks cluster. Without proper agent sandbox isolation, this agent operates with the same permissions as the service account running it—potentially full access to your lakehouse.
LLMs have this unsettling characteristic: they're statistically coherent, not logically infallible. A model can generate code that's syntactically perfect but catastrophic from a business perspective. It can confuse "remove duplicates" with "delete all rows except one". It can interpret "optimize this query" as "completely refactor the business logic".
Isolation isn't just about protecting yourself from errors. It's also about limiting your attack surface. A compromised agent—whether through prompt injection or a flaw in its execution chain—shouldn't be able to access your entire infrastructure. The stakes of AI agents security go well beyond simple technical concerns.
Architecture of a robust sandbox with Docker
Creating an effective sandbox for an AI agent means layering multiple security controls. Docker is one, essential, but insufficient on its own.
The first layer is system isolation. A properly configured Docker container runs with a non-root user, limited kernel capabilities, and a read-only filesystem except for specific temporary directories. For an agent generating dbt code, you mount the project directory as read-only, allow writes only to a dedicated /output folder, and ensure no process in the container can escalate privileges.
Here's what an appropriate Docker for LLM agents configuration looks like for this use case. You define a dedicated user in the Dockerfile, limit capabilities, and mount volumes restrictively:
FROM python:3.11-slim
RUN useradd -m -u 1000 dbt-agent && \
pip install dbt-core dbt-databricks
USER dbt-agent
WORKDIR /workspace
COPY --chown=dbt-agent:dbt-agent requirements.txt .
RUN pip install --user -r requirements.txt
COPY --chown=dbt-agent:dbt-agent agent/ /app/agent/
ENV PATH="/home/dbt-agent/.local/bin:$PATH"
CMD ["python", "/app/agent/main.py"]At runtime, you further strengthen isolation with specific Docker flags. You disable new permissions, limit memory and CPU, and isolate the network except for strictly necessary endpoints:
docker run --rm \
--user 1000:1000 \
--read-only \
--tmpfs /tmp:rw,noexec,nosuid,size=100m \
--security-opt=no-new-privileges \
--cap-drop=ALL \
--network=none \
-v /path/to/dbt/project:/workspace:ro \
-v /path/to/output:/output:rw \
--memory=2g \
--cpus=1.5 \
dbt-agent:latestThis configuration prevents the container from accessing the network by default. For an agent that needs to communicate with Databricks, you create a custom Docker network with only necessary routes, or route through a proxy that filters requests.
The second layer is secrets isolation. An AI agent doesn't need permanent Databricks account credentials. It needs a temporary token, scoped to a specific catalog, with permissions limited to reading and writing certain tables. You generate this token just before the agent executes, inject it via an environment variable (never in code or logs), and revoke it immediately after.
Databricks lets you create service principals with very granular permissions. For an agent generating dbt transformations, you give it read access to a source catalog, write access to a dedicated staging schema, and nothing else. If the agent tries to access a resource outside its scope, the request fails at the lakehouse level, not at the agent level.
Validation and controlled execution of generated code
Isolating the execution environment isn't enough. You also need to validate what the agent produces before executing it. An AI agent generating dbt code can create syntactically correct but semantically dangerous files. Validation needs to happen at multiple levels.
First, you validate the structure. A generated dbt model must follow project conventions: consistent naming, complete metadata, correct references to other models. You can automate this verification with scripts that parse the generated YAML and SQL. If the agent produces a file referencing a non-existent table or missing tests, you reject the result before even attempting compilation.
Next, you compile without executing. dbt lets you validate that a model compiles correctly with dbt compile. This step verifies that model references are consistent, that macros are usable, that the generated SQL is valid for the target engine. You perform this compilation in the Docker sandbox, with read-only access to the Databricks catalog.
If compilation succeeds, you move to a dry-run phase. You execute the model on a minimal subset of data, in an isolated temporary schema. The goal isn't to validate business results—it's to ensure execution doesn't cause runtime errors, doesn't consume excessive resources, and doesn't try to access forbidden resources.
This multi-step approach catches 90% of problems before they reach real data. Generated code passes through four checks: structural validation, compilation, dry-run, then only after human or automated validation of dry-run results, production execution.
A concrete example of a workflow for agentic data pipelines: the agent generates a dbt model that aggregates transactions by customer. The SQL file and YAML are written to the container's /output. An external validation script parses these files, verifies they follow conventions, runs dbt compile in the container. If that passes, you run dbt run --select generated_model --target dev_sandbox on 1000 rows. If the result is coherent, a data engineer validates the model, and only then is it merged into the main repository and run on complete data.
Monitoring and limits: because agents aren't infallible
Even with all these precautions, an AI agent can malfunction. It can loop, generate increasingly absurd code, or fail silently. Monitoring an agent in production looks like monitoring a distributed system: you observe system metrics, application logs, and business results.
On the system metrics side, you monitor CPU, memory, and I/O consumption of the container. An agent generating dbt code shouldn't need 8 GB of RAM. If consumption spikes, it's probably generating something abnormal. You set alerts on these thresholds and automatically kill the container if it exceeds limits.
On the logs side, you capture everything the agent produces: prompts sent to the LLM, responses received, files generated, commands executed. These logs are essential for understanding what happened in case of an incident. You structure them as JSON, send them to a centralized system (Elasticsearch, Datadog, etc.), and apply anomaly detection rules to them.
You also set strict timeouts. An agent generating a simple dbt model shouldn't take more than two minutes. Beyond that, you interrupt execution. You also limit iterations: if the agent tries to regenerate the same model five times in a row because it can't pass validation, you stop the process and alert a human.
Finally, you validate business results. A dbt model that executes without technical errors can still produce incoherent results. You implement automated tests on generated data: expected volume, value distributions, consistency with source data. If a generated model suddenly produces 10 times fewer rows than usual, that's an alarm signal. This approach aligns with principles of semantic validation to prevent analytical errors.
The idea isn't to create a perfect system where no agent can ever make a mistake. That's impossible. The idea is to quickly detect anomalies, limit their impact, and give teams the means to understand what happened. A well-isolated AI agent can fail without endangering the entire system.
Conclusion: isolation as a prerequisite, not an option
Deploying AI agents in production without robust isolation is taking disproportionate risk relative to the automation gains. Docker offers a solid foundation, but an effective sandbox requires multiple layers: system isolation, restrictive secrets management, multi-step validation of generated code, and continuous monitoring.
This approach requires more initial effort than a simple docker run. It imposes constraints on architecture, validation workflows, and how you expose credentials. But it transforms an impressive prototype into a reliable system you can deploy at scale.
AI agents won't disappear from our data pipelines. They'll become more numerous, more autonomous, more integrated into our daily workflows. You might as well learn now how to secure them properly. Because the difference between an agent that efficiently automates your dbt transformations and an agent that accidentally deletes your production catalog often comes down to a few lines of Docker configuration and an architecture designed to limit damage.
```Frequently Asked Questions
Why is Docker alone insufficient to isolate AI agents in production?▼
Docker provides container-level isolation, but doesn't protect against resource leaks, unauthorized file system access, or dangerous system calls. For autonomous AI agents, you need additional sandboxing mechanisms (namespaces, seccomp, AppArmor) to restrict permissions beyond the container and prevent agents from compromising your infrastructure or accessing data from other pipelines.
What security risks do AI agents pose in production without proper isolation?▼
An improperly isolated AI agent can execute malicious code, access sensitive data, consume all system resources, modify critical files, or communicate with unauthorized external services. These risks are amplified in data pipelines where multiple agents share the same infrastructure, creating chain attack vectors and data leaks.
How can you combine Docker and sandboxes to secure AI agents?▼
Use Docker as your first isolation layer, then add system sandboxes: limit system calls with seccomp, isolate the network with network policies, restrict the filesystem with read-only volumes, and control resources with cgroups. This defense-in-depth approach ensures that even if an agent escapes the container, it remains confined within a strict security perimeter.
What sandbox tools should I use alongside Docker for AI data pipelines?▼
Common solutions include gVisor (lightweight sandbox without virtualization), Kata Containers (containers with micro-VMs), Firecracker (for fine-grained isolation), and native Linux tools (seccomp, AppArmor, SELinux). Your choice depends on your acceptable balance between security and performance: gVisor offers good security with minimal overhead, while micro-VMs provide maximum isolation but at greater cost.
How can you monitor and limit AI agent resources in production?▼
Set CPU, memory, and I/O limits via Docker cgroups, and implement active monitoring to detect abnormal overages. Use real-time metrics (memory usage, open file count, network connections) to identify compromised or malfunctioning agents, and schedule automatic termination if critical thresholds are breached to protect your other pipelines.
Related Articles

AI Agents and dbt Pipelines: Where Autonomy Meets Data Orchestration
Artificial intelligence is no longer limited to analyzing data. It's now beginning to orchestrate transformations itself through autonomous AI agents.

How to Extract Reasoning Traces from Proprietary LLMs (and How to Close the Gap)
Large language models expose their internal logic through their APIs. A major risk to intellectual property and security that few organizations are prepared for.

Continuous Evaluation of LLM Systems in Production: Beyond Deployment, Perpetual Improvement
Deploying an LLM is no longer enough. Successful organizations have implemented continuous evaluation mechanisms to drive improvement of their AI systems in production.