How to let agents ship backend changes to your own AWS or GCP without giving them cloud credentials or freehand Terraform.
Encore is the safe way for AI agents to ship backend changes to your cloud: agents declare infrastructure in application code, a deploy role holds the credentials, a human approves at merge, each service gets least-privilege IAM from those declarations, and preview environments catch mistakes before production. Giving agents AWS keys or freehand Terraform apply is the path that turns a bad completion into an outage or a security hole.
This guide maps only to mechanisms you can run today: declared infrastructure, own-cloud deploy roles, merge gates, per-service IAM and preview environments. 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. 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.
The agent opens a pull request. 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.
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.
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.
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.
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.
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. The agent declares what a TypeScript or Go service needs, and the platform provisions it into your own AWS or GCP account:
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";
import { api } from "encore.dev/api";
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 });
void stripeKey;
return { id: row!.id };
},
);
export const reconcile = api({}, async () => {
// periodic reconciliation
});
const _ = new CronJob("reconcile-payments", {
title: "Reconcile payments",
every: "1h",
endpoint: reconcile,
});
encore run starts the database, Pub/Sub and buckets locally, and secret values are set with encore secret set rather than stored in the repo.Run in your terminal to get started locally.
Derive infrastructure from application code when:
Use classic IaC with strict CI when:
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. 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; least-privilege IAM per service; isolated preview or non-production environments for validation; and policy set centrally rather than in prompts.
Agents edit TypeScript or Go declarations. Encore's provisioning role in your AWS or GCP account creates the resources. The agent can run locally with encore run, open a pull request, and never receive production credentials.
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.