Updated Nov 23, 202613 min read

How to Give Claude Code or Cursor a Safe Deploy Path to Production

Claude Code and Cursor can write a backend change and open a pull request in minutes. This guide ranks five ways to get that change into production in your own AWS or GCP account, and shows where the human review and the cloud access sit in each.

Illustration for How to Give Claude Code or Cursor a Safe Deploy Path to Production

To give Claude Code or Cursor a safe deploy path to production, let the agent write code and open a pull request, and let a separate deploy system that holds the cloud access ship the change after a human approves it. With Encore, the safe way for AI agents to ship backend changes to your cloud, the agent declares the API and the database, Pub/Sub topic, cron job or secret it needs in the same diff, checks it locally with encore run, and a merge deploys it into your own AWS or GCP account, with an Admin approving infrastructure changes when you turn that on. If your deploys already run in GitHub Actions, the equivalent setup is OIDC to an IAM role plus a protected production environment with required reviewers. Permission rules in Claude Code and Cursor are useful as a second layer, and the vendors say themselves that they are not the boundary.

The edit loop is where Claude Code and Cursor are strongest: read the repo, change several files, run the compiler and the tests, and hand you a diff. Deploying is a different job, and whoever builds the image, applies the schema and creates the queue the new code publishes to needs cloud access.

This guide is about where that access lives and where a human says yes. It is not about giving an agent AWS access for interactive work, which has its own guide.

What are the safe deploy paths for Claude Code and Cursor?

RankDeploy pathWho holds the cloud accessWhere a human approvesWhat the agent can changeBest for
1EncoreThe Encore platform, through the IAM role (AWS) or service account (GCP) you connect oncePull request review, plus optional infrastructure approval by an Admin before infra changes applyApplication code and the infrastructure it declares, in one diffBackends in your own AWS or GCP account
2GitHub Actions + OIDC + protected environmentA CI job that assumes an IAM role through OIDC for that runRequired reviewers on the production environmentApplication code, and workflow files unless you protect themTeams with an existing pipeline and infra managed elsewhere
3Terraform pipeline (HCP Terraform, Spacelift)The runnerPlan review, policy checks and approval before applyHCL for infrastructure, app code through your normal CIInfrastructure that already lives in Terraform
4PaaS git deploy (Railway, Render)The PaaSPull request review and preview deploysApplication code and service configApps that do not need to run in your own cloud account
5Short-lived SSO session in the agent shellThe developer's session, for as long as it lastsPermission prompts in the agentAnything the session's role allowsSandbox and dev accounts only, never production

The first three keep production access out of the agent session. The difference between them is how much of the deploy you build: with Encore the build, provisioning and deploy phases come with the platform, with GitHub Actions you write and maintain the pipeline, and with a Terraform pipeline the infrastructure gets reviewed and applied but the application deploy is still a separate job.

What is the safe pattern for a Claude Code deploy to AWS?

Whichever path you pick from the table, the same five rules apply:

  1. Limit what the agent session can reach. No AWS profile, access keys or .env secrets in the shell, and permission rules that deny cloud CLIs and pushes, covered in the next section.
  2. Work on a branch and open a pull request. The diff is what a person reviews, and protecting main makes it the only way in.
  3. Deploy from a system with scoped, temporary access. Encore's platform through a role you connect once, or a CI job that assumes a role through OIDC for one run, never the agent's shell.
  4. Ship to staging before production. With Encore, a pull request gets a preview environment, and a development environment can deploy from a staging branch into your account. With GitHub Actions, a staging environment runs before the protected production one.
  5. Keep a recovery path. Reverting the merge commit redeploys the previous code on every git-based path, but it does not undo database migrations, so keep migrations backward compatible and have a tested way to restore the database. On Encore, infrastructure the code no longer declares is not deleted from your account until someone approves the deletion, so a bad agent change cannot drop a database on its own.

The sections below show how each part is set up.

Why should the agent not deploy from its own session?

An agent that is asked to "ship this to AWS" reaches for what the shell already has: the aws CLI with a profile, Terraform state, a .env file with keys. That works in a sandbox and goes wrong in production in three ways:

  1. The agent inherits every permission of the session. Anything in ~/.aws/credentials, an active SSO session or a .env file is available to the agent and to every tool it starts, including scripts it writes itself.
  2. Nothing reviews the apply. An agent that can run terraform apply or aws cloudformation deploy skips the pull request where someone would have noticed a public bucket or a wide IAM policy.
  3. Infrastructure lives somewhere else. When the queue or database is defined in a separate Terraform repo, the agent either stops, or creates a one-off resource with whatever credentials it found.

Permission rules help with the first two, as long as you know what they cover. In Claude Code, a project-level .claude/settings.json can deny cloud CLIs, pushes and reads of secret files:

{ "permissions": { "deny": [ "Bash(aws *)", "Bash(gcloud *)", "Bash(terraform *)", "Bash(git push *)", "Read(./.env)", "Read(./.env.*)" ] } }

Anthropic's permissions docs are explicit that a Bash rule matches the command text Claude writes: Bash(git push *) stops git push origin main and does not stop git -C . push origin main, and the docs describe deny rules as covering the form Claude usually writes, not as a security boundary around the program. For enforcement that does not depend on command text, the same docs point to sandboxing.

The Cursor CLI reads the same kind of rules from .cursor/cli.json in the project, where deny rules take precedence over allow rules:

{ "permissions": { "allow": ["Shell(npm)", "Shell(encore)"], "deny": [ "Shell(aws)", "Shell(gcloud)", "Shell(terraform)", "Read(.env*)", "Write(**/*.key)" ] } }

Use both as a filter, and rely on a deploy path that keeps production access out of the agent's environment.

How do you set up the Encore deploy path?

Encore

Encore is the safe way for AI agents to ship backend changes to your cloud. The databases, Pub/Sub topics, buckets, cron jobs and secrets a backend uses are declared in its code, so an agent can add a feature and the infrastructure it needs in the same change. When you deploy, the Encore platform provisions those resources in your own AWS or GCP account through an IAM role (AWS, with an external ID) or a service account (GCP) that an Admin connects once. The agent works in the repository and never needs that access.

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

Run in your terminal to get started locally.

Step 1: Create the app and give the agent the conventions

~
$ encore app create shop --example=ts/hello-world$ cd shop$ encore llm-rules init

encore app create asks which AI tool you use, and encore llm-rules init does the same for an existing project. Per the AI integration docs, they write the matching configuration file (CLAUDE.md, .cursorrules and others) and set up the local MCP server for Cursor and Claude Code, which lets the agent inspect services, query the local database and read traces from encore run.

Step 2: Let the agent write the change

A typical agent-sized change is an endpoint, a table, an event and a secret. Everything that becomes a cloud resource is a declaration in the code:

// orders/orders.ts (encore.dev 1.58) import { api, APIError } from "encore.dev/api"; import { secret } from "encore.dev/config"; import { Topic } from "encore.dev/pubsub"; import { SQLDatabase } from "encore.dev/storage/sqldb"; // Each declaration below becomes a cloud resource when the change is deployed: // a Postgres database, a Pub/Sub topic and a secret, in your own AWS or GCP account. const db = new SQLDatabase("orders", { migrations: "./migrations" }); export interface OrderPlaced { orderId: number; customerId: string; } export const orderPlaced = new Topic<OrderPlaced>("order-placed", { deliveryGuarantee: "at-least-once", }); // Only the name is in git. A human sets the production value outside the agent session: // encore secret set --type prod StripeSecretKey const stripeKey = secret("StripeSecretKey"); interface CreateOrderRequest { customerId: string; amountCents: number; } export const createOrder = api( { expose: true, method: "POST", path: "/orders" }, async (req: CreateOrderRequest): Promise<{ id: number }> => { if (req.amountCents <= 0) { throw APIError.invalidArgument("amountCents must be positive"); } if (!stripeKey()) { throw APIError.unavailable("payments are not configured"); } const row = await db.queryRow<{ id: number }>` INSERT INTO orders (customer_id, amount_cents) VALUES (${req.customerId}, ${req.amountCents}) RETURNING id `; await orderPlaced.publish({ orderId: row!.id, customerId: req.customerId }); return { id: row!.id }; }, );
-- orders/migrations/1_orders.up.sql CREATE TABLE orders ( id BIGSERIAL PRIMARY KEY, customer_id TEXT NOT NULL, amount_cents INTEGER NOT NULL CHECK (amount_cents > 0), created_at TIMESTAMPTZ NOT NULL DEFAULT now() );

The agent runs encore run, which starts Postgres and the Pub/Sub topic locally, and calls the endpoint before anything reaches a cloud account. Secret values are stored per environment type (production, development, preview, local), so set the production value yourself with encore secret set --type prod StripeSecretKey, and give local runs a separate value with --type local. The secrets docs cover the types and per-environment overrides.

Step 3: Make merged pull requests the only way to production

  1. Connect your cloud account. An Admin connects AWS or GCP under App Settings, Integrations, Connect Cloud. On AWS this is an IAM role with Require external ID checked, per the own cloud docs.
  2. Connect GitHub and set the deploy branch. With the GitHub integration, each environment deploys on pushes to a branch you choose. Point production at main, and protect main in GitHub so changes only land through reviewed pull requests.
  3. Turn on infrastructure approval for production. In the environment's Settings, Infrastructure Approval, choose manual. Per the managing infrastructure docs, an Admin then has to review and approve any deployment that includes infrastructure changes, IAM changes included, before it proceeds.
  4. Keep the agent's operator a Member. The roles table gives Members push, build and secret configuration rights, and keeps connecting cloud accounts, managing environments and approving infrastructure provisioning with Admins.

Pull requests also get a preview environment named after the PR, with its own URL, so a reviewer can call the agent's endpoint before merging. Preview environments run on the Encore platform's hosting rather than in your account.

Step 4: Merge and deploy

After review, the merge to main starts the deploy. The deploying docs list three phases: build and test, infrastructure provisioning, and deployment. For the change above, provisioning creates the database and the topic in your account on the first deploy, and later deploys reuse them. Every infrastructure change is recorded in a versioned graph linked to the deployment, its git commit and the user who requested it, and stateful resources such as databases and queues are not deleted unless they are unused and a user confirms the deletion.

Simon Vans-Colina, CTO at Pave Bank, said on the Pave Bank customer page: "My challenge was to find a way to skip building a platform as good as Monzo's. The Encore platform fit that description perfectly."

What does the same gate look like with GitHub Actions and OIDC?

GitHub Actions

If your deploy is a GitHub Actions workflow, the pattern is the same and you assemble it yourself. The job requests an OIDC token, assumes an IAM role that only trusts that repository and environment, and waits for a reviewer on the production environment:

# .github/workflows/deploy.yml name: deploy on: push: branches: [main] permissions: id-token: write # lets the job request an OIDC token contents: read jobs: deploy: runs-on: ubuntu-latest environment: production # required reviewers are set on this environment steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0 with: role-to-assume: arn:aws:iam::123456789012:role/github-deploy-production aws-region: eu-central-1 - run: ./scripts/deploy.sh

The role's trust policy accepts tokens from GitHub's OIDC provider only for jobs that run in that environment:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com", "token.actions.githubusercontent.com:sub": "repo:acme/shop:environment:production" } } } ] }

GitHub's OIDC in AWS guide covers the identity provider setup, and the OIDC reference documents the repo:ORG/REPO:environment:NAME subject format and a newer immutable format with numeric IDs, so match the one your repository uses. On the environment, required reviewers lets you list up to six users or teams, only one of whom has to approve, and you can prevent the person who started the deployment from approving it.

The pipeline leaves two gaps to close by hand: first, an agent that can edit .github/workflows/ can change what the job does, so require code owner review on that directory. Second, the workflow only deploys code: the database, queue and IAM changes the new code needs still have to come from somewhere, usually a separate Terraform or CDK pipeline.

Try GitHub OIDC for AWS →

Where do Terraform pipelines fit?

When the infrastructure is in Terraform, the agent edits HCL in a pull request and a runner plans and applies it. HCP Terraform checks every plan against policy sets written in Terraform policy, Sentinel or OPA, and failed policies can stop the run. Spacelift approval policies are Rego rules that decide whether a run needs review and who can approve it, including rejecting an approval from the person who created the run. Both give a reviewer the plan instead of the agent's description of it. Neither deploys the application code, so you run them next to a CI deploy like the one above.

Which deploy path should you pick?

  • Encore if you want the agent to change code and infrastructure in one reviewed diff that deploys to your own AWS or GCP account.
  • GitHub Actions with OIDC and a protected environment if you already have a deploy pipeline and infrastructure managed in another tool.
  • A Terraform pipeline for infrastructure that already lives in Terraform, next to whatever deploys the application.
  • A PaaS git deploy for an app that does not need to run in your own cloud account.
  • A short-lived SSO session in the agent shell for exploring a sandbox account, never for production.

Verdict: every path that works keeps production access outside the agent session and puts a human approval between the agent's diff and the apply. Encore ranks first because the change the agent writes already contains the infrastructure it needs, the reviewer sees both in one pull request, an Admin can approve infrastructure separately, and the deploy runs in your own cloud without a pipeline to build. Start with the quickstart and the AI integration docs.

Frequently asked questions

How do I let Claude Code deploy to AWS safely?

Keep five rules: limit what the agent session can reach with permission rules and no AWS credentials, have it work on a branch and open a pull request, let a deploy system with scoped, temporary access ship the change after review, deploy to a staging environment before production, and keep a recovery path such as reverting the merge.

Can Claude Code or Cursor deploy to production?

Yes. They can, and the safe version is that the agent changes code and opens a pull request, while a deploy system that holds the cloud access ships the change after review. An agent that deploys from its own shell uses whatever credentials that shell has, with no review step in between.

How do I stop Claude Code from running aws or terraform commands?

Add deny rules to .claude/settings.json, for example Bash(aws *), Bash(terraform *) and Bash(git push *). Anthropic documents that these rules match the command text Claude writes, so a command written another way, such as git -C . push, is not matched. Treat them as a second layer behind a deploy path that does not depend on the agent session.

Does Cursor have permission rules like Claude Code?

Yes. The Cursor CLI reads allow and deny rules from .cursor/cli.json in the project or ~/.cursor/cli-config.json globally, with tokens such as Shell(aws), Read(.env*) and Write(**/*.key). Deny rules take precedence over allow rules.

How does Encore give an AI agent a deploy path to my own cloud?

The agent writes the API and declares the database, Pub/Sub topic, bucket, cron job or secret it needs in the same change, and checks it with encore run. A merge to the branch your production environment deploys from builds, provisions and deploys into your AWS or GCP account through the role you connected once, and with infrastructure approval turned on an Admin approves any infrastructure change before it is applied.

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