# Should an AI agent hold production secrets?

> AI agents should never hold production secrets. Use limited keys, isolated dev environments, and out-of-band secret links to keep live systems safe.

**No, an AI agent should never hold production secrets or live credentials.** Handing live tokens to an autonomous agent exposes your systems to prompt injection, context window leaks, and unauthorized shell actions. Instead, configure your agent with a scoped, limited key that works against an isolated development environment and routes secret management through human authorization links.

This guide explains the risks of giving secrets to autonomous agents, how scoped API keys protect live systems, and how to safely pass environment variables without revealing them in chat prompts.

## The risks of giving secrets to an agent

Coding tools like Claude Code, Codex, and Cursor operate by reading project files, running terminal commands, and submitting payloads to language models. Giving an agent access to production secrets introduces three major security vulnerabilities:

1. **Context window leakage.** When an agent inspects files containing live credentials (such as a root `.env` file), those values enter the prompt history. The keys are sent across network boundaries to model providers, stored in chat logs, and potentially exposed to anyone who can view the session history.
2. **Prompt injection and untrusted input.** If an agent browses web content, pulls competitor ads, or parses inbound email text, an attacker can embed instructions in that untrusted data. A prompt injection can trick an agent into running a command that exfiltrates local environment variables.
3. **Accidental live mutations.** An agent holding full-access credentials can inadvertently drop production database tables, refund live customer transactions, or delete custom domains while attempting to debug an issue.

To prevent these scenarios, agents need strict guardrails: zero access to production rows, no visibility into live secrets, and an isolated sandbox for testing. For a broader overview of managing agent credentials, read about [one API key for an AI agent](https://thelastapi.dev/blog/one-api-key-for-ai-agent).

## How Limited keys isolate agent workflows

thelastapi separates operational permissions between humans and software agents. When you create an API key or authenticate a tool via OAuth, you select the access tier: **Full access** or **Limited**.

A **Full-access key** (`vz_sk_…`, `access: owner`) can execute every operation on your account. It can read production environment values, issue live refunds, manage DNS records, and delete projects.

A **Limited key** (`vz_sk_…`, `access: agent`) restricts an agent to building, running actions, and deploying code. It defaults to a separate development environment that holds none of your production data.

| Action | Limited key | Full-access key |
| --- | --- | --- |
| Create projects, run builds, and deploy code | Yes | Yes |
| Run actions (scraping, search, SEO audits) | Yes | Yes |
| Call AI models and send transactional email | Yes | Yes |
| Read development database and environment values | Yes | Yes |
| Read production environment values | Names only (`?names=1`) | Yes |
| Read production database rows | No | Yes |
| Execute live refunds, cancels, or withdrawals | No | Yes |
| Create, modify, or revoke API keys | No | Yes |
| Remove live domains or rotate production app keys | No | Yes |

You can generate a Limited key directly from the CLI:

```bash
vibiz keys create growth-agent --limited
```

If you prefer to inspect key permissions or audit existing credentials, check the [keys and environments guide](https://thelastapi.dev/docs/keys) or run `vibiz keys permissions` in your terminal.

## Passing secrets without exposing them in chat

Applications often require third-party keys, such as OAuth app client secrets for Google or GitHub. If you paste those secrets into a chat interface or terminal prompt, you violate basic security hygiene. 

thelastapi provides an out-of-band link mechanism. When an agent determines that an application needs an environment variable, it asks thelastapi for a single-use console link and presents it to you:

```bash
vibiz env link STRIPE_SECRET_KEY
```

In an agent workflow powered by MCP, the agent calls the `vibiz_request_secret` tool:

```json
{
  "project_id": "prj_123",
  "name": "STRIPE_SECRET_KEY",
  "env": "production"
}
```

The tool returns a dedicated URL:

```text
Paste STRIPE_SECRET_KEY here: https://thelastapi.dev/projects/prj_123/secrets/new?name=STRIPE_SECRET_KEY&env=production&kind=env. It goes straight to thelastapi, never through this chat.
```

You open the link in your browser and enter the secret. The value is stored securely and marked as write-only. When your agent inspects project variables with `vibiz env vars` or `GET /v1/projects/:id/env/vars`, it receives only variable names, never raw values.

When your application boots on our hosting or an external server, it retrieves the variables directly:

```ts
import { vibiz } from '@vibiz/app';

// Injects production environment variables into process.env at boot
await vibiz.loadEnv();
```

The running server gets the configuration it needs, but the coding agent that wrote the application never sees the plain text value.

## Working safely with zero production rows

Agents should not test logic against live user data. With thelastapi, every project includes two environments: production and development. Full-access keys default to production, while Limited keys default to development.

When you run `vibiz dev`, the platform provisions an isolated development copy:

```bash
vibiz dev
```

This command creates a `.env.development.local` file containing development credentials. The development environment features:

- **Database branching:** It provisions an isolated database with your production schema and tables, but **zero production rows**. You can learn more about protecting live records in our post on [why agents should never touch production rows](https://thelastapi.dev/blog/agents-never-touch-production-rows).
- **Isolated AI keys:** A dedicated development AI key is injected, preventing development runs from exhausting production rate limits.
- **Payment simulation:** Live payment systems require a 7-day hold before payouts. Development mode routes through test payment endpoints, allowing agents to simulate checkouts, webhooks, and refunds instantly using `vibiz payments simulate`.
- **Sign-in redirection:** Development sign-in trusts `http://localhost:3000` and creates separate development users, leaving live accounts untouched.

When an agent writes tests or runs migrations, it operates entirely within this clean room. If an agent corrupts state, you can reset the copy instantly:

```bash
vibiz dev --reset
```

## Handling permission boundaries and step-up authorization

When an agent using a Limited key attempts an owner-only action—such as reading live database rows or issuing a refund—thelastapi blocks the request and returns a structured error:

```json
{
  "code": "forbidden",
  "details": {
    "reason": "owner_only",
    "permission": "database.production:read",
    "grant_url": "https://thelastapi.dev/keys/key_123/allow?permission=database.production:read",
    "console_url": "https://thelastapi.dev/projects/prj_123",
    "next_step": "Allow this permission at the grant_url, or perform the action yourself."
  }
}
```

The agent does not guess or retry blindly. Workflows configured with the proper [agent skills (SKILL.md)](https://thelastapi.dev/blog/agent-skills-skill-md) will parse `details.grant_url` and output the link for your approval.

You open the grant page and choose one of four paths:
1. **Allow just this:** Grants the single requested permission (for example, `database.production:read`).
2. **Read everything:** Sets the key to the `read_all` preset, letting the agent view live data without granting write or financial permissions.
3. **Full access:** Elevates the key to owner status.
4. **Deny:** Leaves the key restricted.

You can also grant single permissions directly from the command line:

```bash
vibiz keys access key_123 allow database.production:read
```

This step-up model ensures that human oversight remains intact whenever an agent touches sensitive infrastructure.

## Setting up your agent with a Limited key

You can connect Claude Code, Codex, or Cursor to thelastapi using our CLI tools or the remote MCP server.

Configure your client from the [CLI](https://thelastapi.dev/docs/cli):

```bash
vibiz mcp add --clients "Claude Code"
```

For Cursor, configure `.cursor/mcp.json` to connect to the remote MCP server URL:

```json
{
  "mcpServers": {
    "vibiz": {
      "url": "https://thelastapi.dev/mcp"
    }
  }
}
```

On first use, the client initiates an OAuth 2.1 handshake and opens your browser to the Authorize page. Select **Limited** access instead of Full access. The client receives its own key (`cli · <computer name>`), which you can monitor or revoke at any time from the console API keys page.

To learn how to manage agents across full-stack applications, visit the [agents documentation](https://thelastapi.dev/docs/agents). You can create your account at [thelastapi.dev/start](https://thelastapi.dev/start).

## Frequently asked questions

### What happens if an agent tries to read a production secret with a Limited key?

The API returns a `403 forbidden` error with `details.reason: "owner_only"` and provides variable names only (`?names=1`). The secret value is never returned to the agent.

### Can I grant an agent read access to production data without giving it write access?

Yes. You can assign the `read_all` preset or grant specific read permissions like `database.production:read` and `env.production:read` using `vibiz keys access <id> allow <permission>`.

### Where are third-party secrets stored if the agent never sees them?

Secrets entered via `vibiz env link` or the web console are written directly to thelastapi's secure store. They are injected into your running application environment at runtime via `await vibiz.loadEnv()`.

### How does the development database protect live data from an agent?

Running `vibiz dev` provisions an isolated database branch that replicates your schema and tables but contains zero production rows, ensuring agents only work with synthetic data.

---

Published 2026-11-15 · https://thelastapi.dev/blog/should-ai-agents-hold-production-secrets
