When an AI agent runs continuously, it stops behaving like something you occasionally invoke and starts behaving like a system you are responsible for operating, even if most of that operation happens out of sight and without daily attention.
Such a system reads untrusted information, holds credentials, and takes action without waiting for review, which means that the primary risk is rarely an incorrect answer or a strange output, but the agent doing exactly what it was allowed to do in a situation its designers did not fully anticipate.
Most failures in agent deployments are unremarkable in isolation. A token granted during setup remains active longer than intended. Permissions expand to remove friction and are never revisited once things appear stable. Logs quietly accumulate sensitive material because storage is cheap and review is deferred. A retry loop runs until someone notices a cost spike. None of this requires a hostile actor or a novel exploit. It follows naturally from normal work patterns and limited attention.
We will outline a security-first baseline for running AI agents on cloud VMs, including Compute VMs, without tying the approach to a specific framework or tool. The aim is not to prevent every possible failure, but to keep failures contained, visible, and recoverable when they occur.
Hosting location is rarely decisive
Discussions about agent safety often fixate on where the agent runs, as if choosing between a local machine and a cloud VM determines whether the system will behave safely.
In practice, both environments succeed and fail in the same ways. A local system can be tightly scoped and well maintained, or broadly exposed and neglected. A cloud VM can be carefully hardened, or configured in a way that quietly invites trouble. What matters is not location, but scope.
The practical question remains the same in both cases: when the agent behaves badly, intentionally or otherwise, what can it reach, and how quickly can you intervene?
Designing for containment early
Always-on agents benefit from being designed with failure in mind, not because they are inherently unreliable, but because complex systems drift over time in ways that are difficult to notice from the inside.
Isolation is the most dependable starting point. Giving the agent a dedicated VM avoids accidental coupling with unrelated services and personal workflows, and it keeps rebuilds emotionally and operationally cheap, which is an underrated property of resilient systems.
Running the agent as a non-root user further limits the consequences of mistakes. Most useful agent workflows do not require elevated privileges, and when root access becomes a dependency, even small errors can turn into prolonged recovery efforts.
Access control should be intentionally unexciting. Key-based authentication, disabled password logins, and multi-factor authentication on the cloud account reduce the number of ways a system can be reached when something goes wrong. Console access deserves the same scrutiny as SSH, because it bypasses many assumptions people make about perimeter controls.
These steps do not prevent failure. They define how far failure can spread.
Permissions shape behavior more than prompts
Agent deployments tend to fail because of excessive permissions rather than sophisticated manipulation.
When an agent holds credentials that allow broad reading and writing, even a small misunderstanding or misleading input can turn into a significant incident. At that point, containment depends far more on the permission model than on the agent’s reasoning capabilities.
Separate credentials per agent reduce coupling. Narrow scopes reduce unintended reach. Read-only access reduces the cost of mistakes. Rate limits, quotas, and spend caps provide external boundaries when internal logic fails. Together, these controls turn unpredictable behavior into something survivable.
Actions with irreversible impact deserve extra care. If an agent can merge code, delete data, send messages, or trigger payments, introducing human confirmation slows things down in the right place, where the cost of delay is far lower than the cost of cleanup.
Treat secrets as fragile by default
Secrets rarely escape through dramatic breaches. They leave through logs, error messages, screenshots, and convenience-driven shortcuts that accumulate over time.
Keeping secrets out of source control, shared documents, and standard output reduces exposure immediately. A dedicated secrets manager simplifies access control and rotation while encouraging better habits. When local storage is unavoidable, it should be treated as a compromise that requires discipline, with tight permissions, clear separation from the agent’s workspace, regular rotation, and explicit safeguards against printing or logging.
The objective is not theoretical cleanliness. It is to reduce the number of places secrets can end up and to make accidental exposure easier to detect.
Outbound traffic defines the escape path
Inbound controls are familiar and usually addressed early. Outbound traffic receives less attention, even though it determines how data leaves the system.
During early experimentation, unrestricted outbound access is common and often reasonable. As soon as an agent handles sensitive data, outbound paths deserve review. Knowing which destinations the agent needs, observing where it actually connects, and routing traffic through infrastructure you control all make unexpected behavior easier to notice and interrupt.
Containment does not require isolation from the network. It requires that unexpected paths stand out.
Logging with intent
Logs are essential for accountability and diagnosis, but indiscriminate logging creates its own risks.
Event-focused logging strikes a better balance. Tracking start and stop events, tool usage, and external service calls provides operational visibility without creating an archive of sensitive content. Full prompts, transcripts, and document contents feel useful during development, but they often become liabilities later, long after their original purpose has faded.
Some failure modes are specific to agent behavior rather than infrastructure load. Repeated retries, sudden spikes in outbound requests, or sustained resource usage without clear cause often signal looping or misconfiguration rather than demand.
Deciding how the system stops
Operational clarity matters most before deployment, when the system still feels simple.
Knowing how to stop the agent process, shut down the VM from the control plane, and rotate credentials quickly reduces decision-making under stress. Writing these steps down early turns a future incident into a checklist rather than an improvisation.
Isolation and least privilege pay off here. When something goes wrong, the ability to answer what the agent could access, what it could do, and what must be revoked immediately determines how quickly the system becomes understandable again.
A defensible minimum
For teams moving quickly, a small set of controls goes a long way.
- A dedicated VM and a non-root service user limit blast radius.
- Secured administrative access and protected cloud accounts reduce entry points.
- Separate, least-privilege credentials with limits constrain damage.
- Clean logging and disciplined secret handling reduce silent exposure.
- A clear stop-and-rotate plan keeps recovery practical.
Everything beyond this is refinement. Often valuable, sometimes necessary, but still refinement.
An always-on agent is powerful software operating next to your credentials. Treating it as an operational system from the start makes it something you can rely on rather than something you quietly worry about.
