Scoped credentials, sandbox accounts, CI-only deploys and declaring infrastructure in code, compared by what an agent can break and who approves the change.
Coding agents run shell commands, and a shell on a developer laptop usually has whatever the developer has: an ~/.aws/credentials file, a gcloud login, a .env with a database URL.
That goes unnoticed while the agent is editing a React component, but it becomes a real problem the first time it decides the fastest way to fix a failing deploy is to run aws or terraform apply itself, with the developer's admin role, against the account that also holds production.
The agent vendors treat this as a configuration problem, and Codex runs locally with no network access and writes limited to the workspace by default, Claude Code has allow, ask and deny rules for every tool, and Cursor can run terminal commands in a sandbox that blocks unauthorized file and network access. Those controls decide what the agent may run, while the cloud side decides what a credential can do once it is used, and a safe setup needs both.
What to weigh when choosing:
Encore (the safe way for AI agents to ship backend changes to your cloud) combines an open source SDK, where developers and agents declare the databases, Pub/Sub topics, buckets, cron jobs and secrets an application uses in TypeScript or Go, with a platform that provisions them in your own AWS or GCP account through an IAM role or service account you grant and can revoke. Agents declare infrastructure in code, and the cloud access sits with Encore's IAM role, not the agent, so adding a database or a bucket does not require giving the agent a cloud role. The IAM policies, networking and security groups for each resource are generated from the code rather than written by the agent, and deployment settings such as capacity, networking and backups are not part of the declarations an agent edits. This does not make the agent's shell safe on its own: any keys already on the machine still need the permission rules below.

When an agent needs storage for receipts in an orders service, the whole infrastructure change is a declaration next to the code that uses it:
import { Bucket } from "encore.dev/storage/objects";
import { Topic } from "encore.dev/pubsub";
export const receipts = new Bucket("receipts", { versioned: false });
export interface ReceiptCreated {
orderId: string;
key: string;
}
export const receiptCreated = new Topic<ReceiptCreated>("receipt-created", {
deliveryGuarantee: "at-least-once",
});
encore run starts the bucket and the topic locally, so the agent can call the endpoint and read the trace through the local MCP server without any cloud account involved. On deploy, the platform creates an S3 bucket and SNS/SQS on AWS, or Cloud Storage and Pub/Sub on GCP, with an IAM role per service scoped to the resources it uses, following least privilege. Sizing, networking and other settings are managed centrally through infrastructure configuration, outside the code the agent edits.
Approvals sit at the environment level rather than in every command. An environment can require infrastructure approval, in which case an application admin approves new infrastructure before the deployment proceeds, and the platform does not automatically destroy infrastructure that is no longer required, so deleting it requires manual approval in the Encore dashboard. On the Enterprise plan, Encore's own access to your cloud can be just-in-time through GCP Privileged Access Manager.
encore run, and a preview environment per pull request.The agent still needs some access to deploy, which is a git push to Encore or a merged pull request, and roles decide who can push, configure secrets or approve infrastructure. Resources Encore does not model can still be managed directly in your cloud account, and existing databases, buckets and topics can be connected instead of recreated.
Every major coding agent has a way to restrict what it runs. Claude Code evaluates deny rules first, then ask rules, then allow rules, and a project can check its rules into .claude/settings.json, so the whole team gets them:
{
"permissions": {
"deny": [
"Bash(aws *)",
"Bash(gcloud *)",
"Bash(terraform *)",
"Read(~/.aws/**)",
"Read(./.env)"
],
"ask": ["Bash(git push *)"]
}
}
Command patterns filter the agent's behavior rather than limiting the credential, and Claude Code's documentation notes that a deny rule does not match the same program called by its full path or inside sh -c, and recommends pairing deny rules with the sandbox when a restriction must hold. The credential on the machine still has its full permissions if something else uses it, so these rules work best on top of one of the approaches below.
When an agent genuinely needs to call cloud APIs, for example to inspect a resource while debugging, the AWS answer is temporary security credentials from an assumed role, which expire after a set time, in an account that does not hold production. A permissions boundary caps what the role can do even if someone attaches a broader policy later:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket",
"logs:FilterLogEvents",
"cloudwatch:GetMetricData"
],
"Resource": "*"
},
{
"Effect": "Deny",
"Action": ["iam:*", "organizations:*"],
"Resource": "*"
}
]
}
Someone has to design the role, keep the sandbox account in sync with what the app needs and decide when the agent may write rather than read. Once the agent creates resources this way, they exist outside any code review, which is the gap the next two approaches close.
A common pattern for teams already on Terraform or CDK is to keep credentials out of laptops entirely and let CI assume a role through OpenID Connect after a pull request merges:
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::123456789012:role/deploy
aws-region: eu-central-1
- run: terraform apply -auto-approve
production environment can require a reviewer before terraform apply runs.With this setup the agent no longer holds cloud credentials, but it usually still writes the Terraform, IAM policies and security groups that the pipeline applies, and reviewers have to catch an over-broad policy in a generated diff. The only way to test a new resource is often to merge and deploy it, which slows the agent's loop down to the length of a pipeline run. Why letting an agent write infrastructure config is risky covers this in more detail.
Running an agent in a shell that has the developer's own long-lived keys gives it everything the developer can do, in every account the developer can reach, with no expiry. The Stack Overflow 2025 Developer Survey found that more developers distrust the accuracy of AI tools (46%) than trust it (33%), and broad credentials turn that accuracy question into a security one. The minimum change is to remove the keys from the agent's environment or to block cloud CLIs and credential files with deny rules.
Usually not long-lived ones. A safer setup lets the agent describe the infrastructure it needs in code, with a separate system holding the IAM role that provisions it. When an agent does need direct access, use short-lived credentials from an assumed role, scoped to a sandbox account and capped by a permissions boundary, and block cloud CLIs in the agent's own permission rules.
Have the agent declare the resources in application code and let a deploy system with its own IAM role provision them. With Encore, an agent adds a database, topic or bucket as a declaration, runs it locally with encore run, and Encore provisions it in your AWS or GCP account on deploy, optionally after an admin approves the infrastructure change. The cloud access sits with Encore's IAM role, not the agent.
Add a deny rule to the project's .claude/settings.json, for example "Bash(aws *)" under permissions.deny. Deny rules are evaluated before ask and allow rules, so the agent cannot run matching commands even if another rule would allow them.
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.