Updated Nov 10, 202611 min read

Guardrails for AI Agents Provisioning Cloud Infrastructure

Six guardrails for letting agents ship backend changes to your own AWS or GCP, how to apply each one with any tooling, and which platforms enforce them.

Illustration for Guardrails for AI Agents Provisioning Cloud Infrastructure

Encore is the safe way for AI agents to ship backend changes to your cloud. The agent declares the database, queue or bucket in TypeScript or Go, Encore provisions it in your own AWS or GCP account with a role you control, an admin can be required to approve infrastructure changes, Encore provisions an IAM role for the service, or a service account on GCP, and preview environments catch mistakes before production. If you stay on Terraform or Pulumi, put the same guardrails around it with a policy engine such as Spacelift, HCP Terraform or Pulumi policies, and cap everything with AWS Organizations policies. The one setup to avoid is an agent shell with AWS keys or freehand terraform apply.

Agents are now writing a growing share of backend pull requests, and a backend change usually needs infrastructure: a table, a topic, a bucket, a scheduled job. The question is no longer whether agents touch infrastructure, but where the controls sit when they do. This guide covers six guardrails, how to apply each with any tooling, how Encore applies each one, and which platforms enforce them. For the deploy walkthrough see how to let AI agents deploy to AWS. For credential patterns see giving AI coding agents cloud access safely.

What guardrails do AI agents need for cloud infrastructure?

GuardrailWhat it preventsAny toolingWith Encore
Constrained infrastructure surfaceAgent invents IAM, VPCs and resource graphsReviewed modules or templates instead of raw IAM JSON and security-group rulesTyped declarations (SQLDatabase, Topic, Bucket, CronJob, secret) in the service code
Deploy identity holds credentialsAgent laptop holds production keysCI assumes a role through OIDC; no long-lived keys in the agent shellEncore provisions with the role or service account you grant it when you connect the cloud account
Human at mergeUnreviewed production changesRequired pull request review, plus explicit approval for infrastructure changesPull request review, plus optional admin approval for infrastructure changes per environment
One IAM role per serviceOne broad role for every serviceOne role per service, scoped to the resources it usesEncore provisions an IAM role for the service, or a service account on GCP
Non-production validationFirst test happens in productionEphemeral environments per pull request; separate staging and production accountsA preview environment per pull request
Central policyRules that live only in promptsOrganization policies and policy-as-code checks owned by the platform teamEnvironment settings for cloud, approval and infrastructure configuration

Why is giving agents AWS keys or freehand Terraform risky?

Coding agents run shells, and a developer laptop often has ~/.aws/credentials, a gcloud login or a .env with database URLs. The first time an agent "fixes" a deploy by running aws or terraform apply with an admin role, the blast radius is the whole account.

Freehand Terraform has the same failure mode even when credentials sit in CI. Agents produce large diffs, and over-permissioned roles and open security groups pass review because nobody reads generated HCL at that speed. In Spacelift's 2026 survey, a third of infrastructure teams said they would apply AI-generated HCL to production without any review (Spacelift, June 2026).

Agent permission rules (Claude Code deny lists, Codex sandboxing, Cursor terminal sandbox) are necessary but not sufficient. You also need a cloud-side path where infrastructure changes do not require the agent to hold cloud power.

How do you apply each guardrail?

1. How do you constrain what the agent can change?

Give the agent a small, typed or templated surface for infrastructure, and keep IAM policies, network rules and account-level resources out of the files it edits by default. Use agent permission rules to deny aws, gcloud, terraform apply and kubectl in the agent shell.

With Encore: the surface is the set of infrastructure declarations in the service code. The agent adds new Bucket("receipts") the same way it adds an API handler, and there is no IAM, VPC or security-group file for it to edit.

2. Where should the cloud credentials live?

The agent opens a pull request, and CI or a deploy system with its own role, assumed through OIDC or workload identity federation, applies the change. The agent's environment does not need AWS_ACCESS_KEY_ID, and you can revoke the deploy role without touching developer machines.

With Encore: you connect your AWS or GCP account once and grant Encore an IAM role (on GCP, a service account). Encore provisions with that role when a change deploys. Cloud access sits with Encore's IAM role, not the agent. On GCP you can scope that access down to a single project.

3. Where does the human approve?

A person reviews the application change and the infrastructure it needs together, exercises it in a running environment and merges. For production, require a second, explicit approval for deploys that create, change or delete infrastructure, and keep code-only deploys automatic.

With Encore: an environment can require infrastructure approval, so an app Admin approves the infrastructure changes before the deploy proceeds. Encore also does not delete infrastructure without a manual approval in the dashboard, even if the agent removes a declaration.

4. How should IAM be scoped?

Give each service its own role with access only to the resources it uses. A payments service that uses one database, one bucket and one topic should not inherit permissions for queues in another service. Review generated policies for wildcards in actions and resources.

With Encore: Encore provisions an IAM role for the service, or a service account on GCP. The role follows the declarations, so when the agent adds a bucket to the payments service, nobody writes a policy for it and nobody widens a shared role by hand.

5. Where do changes get tested before production?

Each pull request should get an isolated environment, or at least a non-production account, where reviewers can hit a live API. Staging and production stay separate, with separate credentials.

With Encore: each pull request can get a preview environment, hosted by Encore, with its own infrastructure, torn down when the pull request is merged or closed. Locally, encore run starts the same declarations against Postgres in Docker and an in-memory Pub/Sub broker, so the agent can test before it opens the pull request.

6. Where should policy live?

Decisions that should not live in every agent prompt:

  • Which cloud accounts and regions are allowed for automatic provisioning
  • Whether new infrastructure needs an explicit approval in each environment
  • Whether deletions require manual approval
  • Which compute option and instance sizes each environment allows
  • How preview environments are created and torn down

Agents then work inside those boundaries, and the team changes policy in one place instead of rewriting prompts after every incident.

With Encore: these are environment settings (cloud provider, approval, process allocation) and infrastructure configuration for sizing, networking and backups, set by the team rather than by the code the agent writes.

Which platforms govern AI agents that provision infrastructure?

RankPlatformWhere the guardrail sitsAgent holds cloud credentials?Best for
1EncoreAt the source: agents can only declare supported resources in code; Encore provisions in your own AWS or GCPNoTypeScript and Go backend teams that want agents shipping backend changes
2SpaceliftOn IaC runs: OPA policies on plans, approvals and drift detectionNoif runs use Spacelift's cloud integrationTeams with Terraform, OpenTofu or Pulumi that agents will edit
3HCP TerraformOn Terraform runs: Sentinel or OPA policy checks before applyNoif the workspace holds the credentialsTeams standardized on HashiCorp tooling
4PulumiOn Pulumi deployments: policy packs that run during preview and updateDepends on where pulumi up runsTeams writing IaC in TypeScript, Python or Go
5AWS Organizations (SCPs, permissions boundaries)In the cloud: a ceiling on what any role can doNot applicable; it constrains whoever doesEvery AWS team, as the floor under the other four

The ranking is by how early the guardrail applies, and Encore removes the agent's ability to invent infrastructure in the first place. The IaC policy engines review what the agent wrote and block bad plans. Organization policies stop the worst outcomes no matter which tool made the call, so use them with any of the others.

How do the common approaches compare?

ApproachAgent holds cloud creds?Who writes IAM / networking?ApprovalBlast radius
Infrastructure derived from application code (Encore)Nofor infra changesGenerated from declarationsHuman at merge; optional infra approvalResources the code declares, in the target environment
Agent writes Terraform, policy engine in CIUsually no long-lived keys; CI role has broad accessThe agent (or a person cleaning up)PR review of HCL diffs plus policy checksWhatever the CI role can change, minus what policy blocks
Scoped short-lived agent credentialsYestemporaryPerson ahead of timeBoundary onlySandbox account if configured correctly
Developer admin credentials in the agent shellYesoften broadThe agent, if it wantsNoneEverything the developer can reach

For permission-rule examples and OIDC CI patterns, use give AI coding agents cloud access safely.

What does an agent's infrastructure change look like with Encore?

Encore

Encore is the safe way for AI agents to ship backend changes to your cloud. Here is a payments service an agent might write. Everything it needs from the cloud is a declaration, and nothing in the file is an IAM policy or a network rule:

import { api } from "encore.dev/api"; import { SQLDatabase } from "encore.dev/storage/sqldb"; import { Topic } from "encore.dev/pubsub"; import { Bucket } from "encore.dev/storage/objects"; import { secret } from "encore.dev/config"; import { CronJob } from "encore.dev/cron"; const db = new SQLDatabase("payments", { migrations: "./migrations" }); const receipts = new Bucket("receipts", { versioned: false }); const stripeKey = secret("StripeSecretKey"); interface PaymentCaptured { paymentId: string; } export const paymentCaptured = new Topic<PaymentCaptured>("payment-captured", { deliveryGuarantee: "at-least-once", }); export const capture = api( { expose: true, method: "POST", path: "/payments" }, async (req: { amount: number }): Promise<{ id: string }> => { const row = await db.queryRow<{ id: string }>` INSERT INTO payments (amount) VALUES (${req.amount}) RETURNING id::text AS id`; await receipts.upload(`${row!.id}.json`, Buffer.from(JSON.stringify(req))); await paymentCaptured.publish({ paymentId: row!.id }); return { id: row!.id }; }, ); // Compares the last day's payments with Stripe. export const reconcile = api({}, async (): Promise<{ checked: number }> => { const res = await fetch("https://api.stripe.com/v1/charges?limit=100", { headers: { Authorization: `Bearer ${stripeKey()}` }, }); const body = (await res.json()) as { data: unknown[] }; return { checked: body.data.length }; }); const _ = new CronJob("reconcile-payments", { title: "Reconcile payments", every: "1h", endpoint: reconcile, });

When that pull request merges, Encore provisions the Postgres database, the bucket, the SNS topic and the Secrets Manager entry in your AWS account (Cloud SQL, Cloud Storage, Pub/Sub and Secret Manager on GCP). Encore provisions an IAM role for the service, or a service account on GCP. The Encore platform runs the cron job on schedule in deployed environments, with no scheduler for you to configure. If the environment requires infrastructure approval, the deploy waits for an Admin. Have a person set the secret value with encore secret set, so it stays out of the repo and out of the agent's context.

How do you try it?

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create agent-safe --example=ts/hello-world$ cd agent-safe$ encore secret set --type dev,local StripeSecretKey$ encore run

When is each model the right fit?

Derive infrastructure from application code when:

  • Backend services need databases, queues, object storage, cron or secrets
  • You want agents to ship those changes without cloud keys on laptops
  • Production must stay in your own AWS or GCP account
  • A person can review application PRs that include infrastructure declarations

Use classic IaC with a policy engine when:

  • Most changes are org-level networking or specialized services an application-level tool does not model
  • A platform team owns a large Terraform or Pulumi estate and application teams should not declare cloud resources

Verdict. For backend teams letting agents write TypeScript or Go services, Encore puts the guardrails where the agent works: it can declare resources, not invent IAM, and your own cloud account stays under a role you control. If your agents edit Terraform or Pulumi, add a policy engine before apply, and use AWS Organizations policies as the floor in either case.

If your agents already write most of your backend pull requests, start with Encore on one service: the agent declares what it needs, you review the pull request and the preview environment, and the deploy lands in your own AWS or GCP account.

Frequently asked questions

How do I let AI agents provision infrastructure in our AWS account safely?

Do not give agents long-lived AWS keys or freehand terraform apply. Have agents declare databases, queues, buckets, cron jobs and secrets in application code or a reviewed module interface. A deploy system with its own IAM role provisions those resources in your account after a human merges.

Should AI agents ever hold production cloud credentials?

Prefer no. Keep cloud access on a deploy role the agent does not control. If an agent must call cloud APIs directly, use short-lived credentials in a sandbox account with a permissions boundary, and deny cloud CLIs in the agent permission rules.

What guardrails matter most for agent-driven infrastructure changes?

Six: a constrained infrastructure surface instead of improvised cloud config; credentials held by a deploy identity; a human at merge; one IAM role per service; isolated preview or non-production environments for validation; and policy set centrally rather than in prompts.

Which platforms govern AI agents that provision infrastructure?

Encore enforces the guardrails at the source: agents declare infrastructure in TypeScript or Go, Encore provisions it in your own AWS or GCP account with its own role, and environments can require admin approval for infrastructure changes. Spacelift, HCP Terraform and Pulumi add policy checks and approvals on top of IaC that an agent or a person writes. AWS Organizations service control policies and permissions boundaries set a hard ceiling under all of them.

What is the difference between this and letting an agent write Terraform?

Freehand Terraform lets the agent invent IAM, networking and resource graphs. Reviewers rarely catch subtle over-permissioning at agent speed. Declarations in application code produce the same IAM and networking every time for a given set of resources, so the review surface is the app change, not a generated script.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders