Skip to content

The Deska blog

Running Agents on Infrastructure Code

Learn how to safely deploy and manage AI agents on infrastructure code repositories using local-first tools and secure workflows.

10 min read

The shift toward automated cloud management has introduced a new paradigm where developers use autonomous AI agents to manage complex infrastructure code. When running agents on infrastructure code, the stakes are significantly higher than in standard application development. A hallucination in a React component might break a UI layout, but a mistake in a Terraform provider configuration or a VPC peering module can result in catastrophic downtime or security vulnerabilities. This guide explores the technical architecture required to run agents safely, the tools available for the task, and how to maintain human-in-the-loop control over your cloud resources.

The Architecture of Infrastructure Agents

Autonomous agents differ from simple autocomplete tools because they can execute commands, read files, and iterate on errors. When dealing with infrastructure as code, the agent requires a specific set of capabilities to be effective. It needs access to the CLI tools like terraform, terragrunt, or crossplane. It also needs the ability to parse plan outputs and understand the dependency graph of your resources.

Safety becomes the primary concern when these agents are granted write access to a repository. Most teams adopt a layered security model. The agent operates in a local or sandboxed environment where it can run terraform plan but cannot execute terraform apply without an explicit manual trigger. This ensures that the agent proposes changes while the engineer remains the ultimate authority for deployment.

Popular Agents for DevOps Workflows

Several agents have emerged as leaders in the space of terminal-based code manipulation. Each has a different philosophy regarding how it interacts with your local environment and your cloud credentials.

Claude Code and Codex CLI

Claude Code is a research preview from Anthropic that operates directly in your terminal. It is highly capable at reasoning through complex file structures and can execute commands to validate its own work. For infrastructure tasks, this means it can run a plan, identify a missing variable, search through your modules to find the correct value, and update the .tfvars file accordingly.

Codex CLI focuses more on the translation of natural language into shell commands. While less "autonomous" in the sense of long-running agents, it is excellent for quickly generating complex HCL (HashiCorp Configuration Language) blocks without leaving the command line.

OpenCode

OpenCode provides an open-source alternative for developers who want more control over the underlying model and the execution environment. It is particularly useful for teams with strict compliance requirements who may want to point their agent at a specific internal LLM endpoint rather than a public API.

Managing the Agent Workspace

The environment where an agent runs is just as important as the model itself. A messy workspace leads to context fragmentation. Developers need a way to see the agent's thought process, the terminal output it is generating, and the resulting code changes simultaneously.

Deska provides an infinite canvas workspace designed for this exact purpose. Instead of juggling multiple terminal tabs, you can place panels for your code editor, multiple terminals, and agent sessions side by side. This visual organization is critical when running agents on infrastructure code because you can monitor the agent in one panel while keeping a live view of the main.tf file and a browser window with your cloud provider's documentation in others.

You can learn more about how this works by visiting the canvas page or exploring the documentation on panels. This setup allows for a local-first approach where all your sensitive cloud credentials and state files remain on your machine rather than being synced to a third-party cloud IDE.

Safety and Security Best Practices

When integrating agents into your DevOps workflow, follow these security principles to minimize risk:

  • Keep credentials local: Avoid hardcoding secrets in your infrastructure files. Use local environment variables that the agent can access but not necessarily modify or export.
  • Use local-first tools: By keeping the files and execution local, you reduce the attack surface. Tools that prioritize local-first data storage ensure your architecture diagrams and state files aren't stored on external servers.
  • Review plan outputs: Always inspect the output of a plan command generated by an agent. Look specifically for destroyed resources or changes to IAM policies.
  • Limit agent scope: Point the agent at specific subdirectories or modules rather than the root of a massive monorepo to prevent it from making unintended global changes.

Integration with Deska

Deska is a free desktop app for Mac, Windows, and Linux that serves as a specialized environment for these agents. It supports running Claude Code, Codex CLI, and OpenCode as dedicated panels. This allows you to interact with multiple agents at once, comparing their suggestions for a specific infrastructure problem.

One of the unique features is Ask Deska, a voice and chat assistant that can drive the entire workspace. You can use your voice to tell Deska to open a new terminal, run a terraform init, and start an agent session. This reduces the cognitive load of managing the tools, allowing you to focus on the infrastructure logic.

For engineers who need to step away from their desks, the mobile app allows you to monitor long-running agent tasks. You can pair your phone directly with your desktop through a secure relay. This does not require exposing any ports on your router, making it a secure way to check if an agent has finished generating a complex set of cloud resources while you are away.

Comparison of Infrastructure Tooling Approaches

FeatureStandard CLICloud IDEDeska Workspace
PrivacyHigh (Local)Low (SaaS)High (Local)
Multi-Agent SupportManualLimitedNative Panels
InterfaceSingle TerminalTabbedInfinite Canvas
Mobile MonitoringNoneBrowser-basedSecure Native Relay

FAQ

How to use Claude Code for Terraform?

To use Claude Code with Terraform, you should install the agent locally and run it within your repository. You can then issue commands like "Refactor this VPC module to support three availability zones." The agent will read your existing HCL files, suggest changes, and you can instruct it to run terraform plan to validate the syntax and logic before you commit the changes.

Are AI agents safe for cloud infrastructure?

AI agents are safe for cloud infrastructure when used with a human-in-the-loop workflow. You should never allow an agent to perform an "apply" command automatically. By running agents in a local-first environment like Deska, you ensure that your sensitive state files and API keys are never uploaded to the agent provider's servers, maintaining a high level of security.

What is the best AI agent for DevOps?

The best agent depends on your specific needs. Claude Code is currently excellent for deep reasoning and multi-file edits. OpenCode is a strong choice for those who prefer open-source tools. Many developers find that running these agents side by side in a unified workspace provides the best results, as they can cross-reference the output from different models.

Conclusion

Running agents on infrastructure code represents a significant leap in productivity for DevOps engineers. By automating the boilerplate of HCL and the tedious parts of resource configuration, teams can focus on higher-level architecture. However, the power of these tools must be balanced with strict security practices and a local-first mindset.

If you are looking for a workspace that brings your terminals, editors, and AI agents into a single, organized environment, you can download Deska for free. It provides the infrastructure necessary to run these modern agents safely on your local machine while giving you the flexibility of an infinite canvas to manage your cloud projects.