Self-Hosted AI Agents: What Control Can Enterprises Actually Retain?
Self-hosting an AI agent does not automatically mean that no data leaves the enterprise network. This article distinguishes data retention from data transmission, breaks down the sandbox execution, service and control plane, and model inference layers, and compares fully managed, self-hosted sandbox, and self-hosted service deployments. It also examines how self-hosting interacts with zero data retention (ZDR) requirements and offers practical recommendations for architecture review, sensitive-data filtering, and cloud infrastructure use.
As large language models evolve from simple text interaction toward AI agents that can execute complex tasks, enterprise requirements for infrastructure are changing significantly. While enterprises want the automation benefits that agents provide, data security, credential management, and compliance retention have become difficult issues for IT architects. Recently, the concept of “self-hosted AI agents” has emerged, and many teams expect it to mean that data never leaves their network. A deeper look at the architecture shows that self-hosting is not a universal solution. This article examines the nature of self-hosted AI agent services, clarifies what control enterprises can actually regain, and identifies which external dependencies they must still accept.
1. Clarifying the Core Misconception: The Boundary Between Data Retention and Data Transmission
When evaluating any AI agent hosting service, the most easily confused concepts are “data retention” and “data transmission.” Many project reviews answer the question “does data leave our domain?” with a simple yes or no, missing a critical security review step.
In fact, these two concepts should be strictly separated:
- Data retention: Where persistent data such as conversation history, user credentials, and agent state is stored, and who is responsible for access control and scheduled deletion.
- Data transmission: What data the client or server must send externally during model inference. This includes not only the user’s prompt but also the full conversation context up to that point, the input parameters for tool calls, and the results returned after tool execution.
When an enterprise claims to use a “self-hosted” solution, it usually means the enterprise has taken responsibility for data retention—for example, the database is deployed inside the enterprise network. However, this does not mean the data transmission path has been cut. As long as the AI agent’s inference engine is still provided by an external vendor, the full conversation context must pass through an external inference path on every model call. Confusing these two concepts can easily leave hidden risks in security and compliance audits.
2. Three Core Layers of AI Agent Hosting Architecture
To understand the boundaries of self-hosting, it is necessary to separate the AI agent infrastructure into layers. A complete AI agent system can usually be divided into three relatively independent layers:
- Sandbox execution layer: An isolated environment where tools execute commands and operate on files. When an agent executes code, queries a database, or operates on a file system, it must do so in a sandbox to prevent damage to the host machine.
- Service and control plane layer: Responsible for receiving API requests, managing the agent’s run loop such as the ReAct loop, maintaining short-term memory, scheduling tools, and persisting sessions and state storage. This is the “central nervous system” of the agent.
- Model inference layer: The foundation model layer, responsible for understanding intent, performing logical reasoning, and generating responses or tool-call instructions.
These three layers are logically decoupled, which makes AI agent deployment flexible and enables enterprises to self-host selected components as needed.
3. In-Depth Comparison of Three Deployment Models
AI agent hosting services in the industry typically offer three progressive deployment models. Enterprises can choose based on their security requirements and technical capabilities.
Model 1: Fully Managed (Cloud Sandbox)
This is the most basic default model. In this model, the sandbox, service and control plane, and model inference layer are all managed by the cloud vendor. Enterprises only need to call the API to use the full agent capabilities. This model has the lowest development cost, but conversation history and state data are stored on the vendor side. It is suitable for scenarios with low data retention requirements and a need for rapid validation.
Model 2: Self-Hosted Sandbox
As security requirements increase, enterprises can choose to move the sandbox execution layer into their own environment. In this model, tool execution and file operations take place in customer-controlled containers or virtual machines, which effectively prevents sensitive files from being read directly. However, the service and control plane and model inference are still managed by the vendor, and conversation history is still stored in the cloud.
Model 3: Self-Hosted Service
This is currently the highest level of self-hosting. The enterprise controls not only the sandbox but also the service and control plane. This means API management, the agent run loop, conversation history, and credential management all reside in the enterprise’s own database. For the model inference layer, the enterprise can continue using the original vendor or switch to another inference provider. This model is particularly suitable for teams that are blocked by retention ownership and credential management issues. For example, enterprises can use Baidu AI Cloud’s container platform and object storage to build this self-hosted service layer, giving them full control over the lifecycle and deletion policies of session data.
4. Compliance Boundary Between Self-Hosting and Zero Data Retention (ZDR)
When discussing self-hosting, one concept that cannot be avoided is ZDR (Zero Data Retention). ZDR is typically used to require that a vendor must not retain request data in logs, caches, or any storage medium after responding to an API request.
In the “fully managed” and “self-hosted sandbox” models, sessions are saved by the vendor, and the vendor-hosted ZDR exclusions often apply. However, when an enterprise upgrades to the “self-hosted service” model, conversation history is placed in its own database, so the exclusion for hosted-service session storage no longer applies.
There is still a key blind spot here: a self-hosted service does not automatically qualify all model requests for zero retention. Model inference requests still need to be sent to an external inference provider, and the retention policy during transmission and inference depends entirely on the model used, the features enabled, and the provider’s policies and contractual terms. For example, some models use optimization mechanisms such as KV Cache to improve inference speed, which may retain part of the context for a short period. Therefore, enterprises cannot infer final data security conclusions solely from the deployment model—whether self-hosted or not. They must check the ZDR documentation and exception clauses separately for each specific model and provider.
5. Practical Recommendations for Enterprise Self-Hosted Deployments
Based on the analysis above, enterprises should adopt a more rigorous review mechanism when planning AI agent architecture:
- Build a two-dimensional checklist: During project review, complete a “retention checklist” and a “transmission checklist” separately. The retention checklist should specify the physical location of the database, access permissions, and scheduled cleanup mechanisms. The transmission checklist should specify the destination address of requests, the transport protocol such as TLS encryption, and the payload contents.
- Pre-filter sensitive information: Because inference requests inevitably send context externally, it is advisable to add a data masking or filtering gateway at the service and control plane layer. Before calling an external model, mask sensitive fields in tool results, such as ID numbers and trade secrets.
- Make full use of cloud infrastructure: For enterprises that choose a self-hosted service, existing cloud-native capabilities should be used. For example, Baidu AI Cloud’s log service can be used to audit every tool call made by the agent, and a key management service (KMS) can securely store credentials for external model APIs. This helps maintain control while reducing operational burden.
In summary, self-hosted AI agent services give enterprises finer-grained control, allowing them to retain ownership of sessions and credentials while still using foundation model capabilities. However, “data never leaves the network” must not be treated as a blind promise of this technical approach. Only by thoroughly understanding the layered logic of sandbox, service, and model inference—and by strictly separating the retention and transmission paths—can enterprises build AI agent applications that are both efficient and compliant.
