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.

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.
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.
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.
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.
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.
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.
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.
Decisions that should not live in every agent prompt:
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.
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.
For permission-rule examples and OIDC CI patterns, use give AI coding agents cloud access safely.
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.
Run in your terminal to get started locally.
Derive infrastructure from application code when:
Use classic IaC with a policy engine when:
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.
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.
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.
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.
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.
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.