Updated Nov 5, 20266 min read

How to Let AI Agents Deploy Safely to AWS or GCP

Deterministic provisioning from application code, a deploy role that holds credentials, and a human at the merge so agents ship to your own cloud without improvising infrastructure.

Illustration for How to Let AI Agents Deploy Safely to AWS or GCP

Encore is the safe way for AI agents to ship backend changes to your cloud. The agent declares infrastructure in application code, Encore provisions IAM, networking and managed services deterministically in your own AWS or GCP account, and a person approves the change at merge. An agent that improvises IAM policies, networking and deployment scripts can cause an outage or a security hole with one mistake.

This guide covers why freehand cloud config is risky, how deterministic provisioning works, where the human stays, and how to keep existing AWS or GCP infrastructure while you adopt the path. For the policy checklist see guardrails for AI agents provisioning cloud infrastructure. For credential patterns see giving AI coding agents cloud access safely.

Why is letting an agent write infrastructure config risky?

IAM, networking and resource configuration are unforgiving and easy to get subtly wrong. An agent producing them freehand can create an over-permissioned role or an exposed resource that passes review, because nobody reads generated Terraform closely at agent speed. In Spacelift's 2026 survey of 406 infrastructure decision-makers, 78% said they use AI to generate infrastructure as code without thorough review, and a third said they would apply AI-generated HCL to production without any review (Spacelift, June 2026).

Agent output arrives faster than anyone can review cloud configuration line by line. The better fix than reviewing harder is to take freehand cloud config out of the agent's job.

What does a safe deploy path for agents look like?

These controls work with any toolchain, whether you use Terraform in CI, CDK, Pulumi or a platform:

  1. The agent describes intent, not cloud wiring. Give the agent a constrained surface such as reviewed modules, templates or typed resource declarations, and keep raw IAM JSON and security-group rules out of its default edit path.
  2. Generation is deterministic. The same input should produce the same plan every time, so reviewers can reason about a change from a small diff instead of re-reading a full plan.
  3. A deploy identity holds the credentials. CI or a deploy system assumes a role through OIDC or a similar short-lived mechanism. The agent's shell has no long-lived cloud keys.
  4. Policy lives outside the agent's loop. Allowed accounts, regions, instance sizes and deletion rules sit in a place the platform team controls, such as SCPs, policy-as-code checks or environment settings, not in prompts.
  5. The change runs before production. The agent tests against local or ephemeral infrastructure, and reviewers can hit a running preview or staging environment.

Where does the human stay?

A person stands at the merge, confirming the change works by exercising it in a running environment before merging. Deployment after that is automatic. Keeping the human at the merge rather than at every deploy step means one review per change, and that review covers the application change and the infrastructure it needs in the same diff.

For production, add a second gate for the riskiest class of change: require explicit approval when a deploy creates, changes or deletes infrastructure, and keep ordinary code-only deploys automatic. How to give agents infrastructure to test against is covered in how to give AI coding agents real infrastructure.

Does this have to run in your own cloud?

It should. Running in your own AWS or GCP account keeps resources under your IAM, billing, logging and audit controls rather than a vendor's production host. It also lets you adopt the path service by service next to existing VPCs, clusters and databases instead of migrating everything at once.

What should you not do?

  • Do not put long-lived AWS keys in the agent's environment for production work.
  • Do not ask the agent to author Terraform or IAM JSON as the primary path for application databases, queues, buckets, cron or secrets.
  • Do not skip pull request review because the diff "looks like application code." Infrastructure declarations ship in that same diff on purpose.
  • Do not rely on agent permission rules alone. Deny lists and sandboxes help, but the cloud side also needs a path that does not hand the agent cloud power.

How does Encore handle agent deploys?

Encore

With Encore, resources declared in TypeScript or Go application code are read by the deploy system, which derives the required infrastructure from static analysis. For a change that needs a database, object storage, a queue, a cron job and an API key held as a secret, the agent writes declarations next to the handlers:

import { api } from "encore.dev/api"; import { SQLDatabase } from "encore.dev/storage/sqldb"; import { Bucket } from "encore.dev/storage/objects"; import { Topic, Subscription } from "encore.dev/pubsub"; 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({ amount: req.amount })), ); await paymentCaptured.publish({ paymentId: row!.id }); void stripeKey; return { id: row!.id }; }, ); export const reconcile = api({}, async () => { // periodic reconciliation against the provider }); const _fulfill = new Subscription(paymentCaptured, "fulfill-payment", { handler: async (event) => { // Idempotent fulfillment keyed by event.paymentId }, }); const _ = new CronJob("reconcile-payments", { title: "Reconcile payments", every: "1h", endpoint: reconcile, });

On AWS, the deploy system provisions the database, the bucket, the Pub/Sub topic and subscription wiring, the secret and the networking. Cron jobs are triggered by the Encore platform, so they need no extra cloud resources. Encore provisions an IAM role for the service (on GCP, a service account). The agent never writes that layer, and reviewers reason about what a change provisions by reading the declarations.

The agent
  • Writes the feature code
  • Runs and tests it until it works
  • Opens a change ready to review
You and the platform team
  • Decide what to build
  • Review the result and approve what ships
  • Set the guardrails: permissions and deployment policy

Encore runs in your own AWS or GCP account. You can deploy to Kubernetes on a new GKE or EKS Fargate cluster in your account. Importing an existing Kubernetes cluster is supported on GCP, and AWS support is listed as coming soon. Existing AWS resources such as RDS databases can be imported. Production environments can require admin approval for infrastructure changes, and instance sizes, networking and backups live in environment configuration, outside the application files agents edit by default. Preview environments can expose a live API per pull request.

How do you get started?

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

Run in your terminal to get started locally.

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

Connect AWS or GCP in the dashboard, grant the provisioning role, and let the agent open a pull request that adds a declaration. Confirm the agent never needed production cloud keys to propose the change.

When should you pick which path?

  • Pick a platform that derives infrastructure from application code when agents should add application infrastructure in your own AWS or GCP account without holding cloud credentials.
  • Pick CI-only Terraform or CDK with OIDC when a platform team owns a separate IaC estate and agents should not declare cloud resources in app code.
  • Pick scoped sandbox credentials only when the agent must call cloud APIs directly, and keep production out of that account.

For the full guardrail checklist, use guardrails for AI agents provisioning cloud infrastructure.

Frequently asked questions

Is it safe to let AI agents deploy to production?

It can be, when the agent never writes cloud configuration by hand. With infrastructure derived deterministically from application code, credentials held by a deploy role, guardrails set centrally, and a person confirming the change at merge, deployment is a repeatable step rather than something the agent improvises.

Does the agent write the Terraform or IAM policies?

No. The agent writes application code and infrastructure declarations. The deploy system derives IAM, networking and provisioning from static analysis of that code. The same declarations produce the same configuration every time.

Should the deploy path run in my own cloud account?

Usually yes. Resources in your own AWS or GCP account stay under your IAM, billing and audit controls, and you can adopt an agent deploy path service by service next to existing infrastructure instead of moving everything to a vendor's production host.

How do AI agents deploy to AWS with Encore without AWS keys?

The agent declares Postgres, queues, buckets, cron jobs and secrets in TypeScript or Go, tests with encore run locally, and opens a pull request. After merge, Encore's provisioning role in your AWS account creates the resources. The agent never needs production credentials for that path.

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