---
title: "Postgres for AI agents | Xata"
description: "Let your agents create, use and delete their own Postgres databases through the API, CLI or MCP server. A database per task, scoped keys, and idle databases that scale to zero."
source: "https://xata.io/use-cases/agent-sandboxes"
---

# Postgres your agents create for themselves

The database primitives agents need: a Postgres per task, created through the API, CLI or MCP server, that costs no compute when nobody is using it.

[Hand setup to your agent](/docs/ai-agents/onboarding)[Get started](https://console.xata.io/signup)

### Postgres for AI agents

Agents create, query and delete Postgres databases through the API, CLI or MCP server, with scoped keys and scale to zero built in.

### Ready for AI-assisted coding

Claude Code, Cursor, Codex and other coding agents work with Xata through the MCP server and CLI.

### Quick to start

Hand setup to your coding agent. It installs the CLI, creates a project and connects your app.

### [Building a platform that gives your users Postgres?](/solutions/platforms)

[White-label Postgres with branching and scale to zero.](/solutions/platforms)

[See Platforms](/solutions/platforms)

Add a database to your agent

## Provisioning is one call

An agent that needs a scratch database should not wait on a ticket or share one with every other run. With Xata it creates one when the task starts and deletes it when the task ends.

$ xata branch create --name my-test --no-parent

✓ Postgres ready · ~1s

postgresql://xata@db.xata.tech/my-test

Agent workloads

## Many short-lived databases, no idle bill

Instead of one database that lives for years, agents create many that live for minutes. Fast provisioning makes that practical, and scale to zero keeps the idle ones from adding up.

One database per task

### Ready in seconds

A new database is ready in about a second. A branch with a copy of real data takes about three.

### Idle databases cost nothing

Turn on scale to zero and an idle database releases its compute. The next connection wakes it.

448 branches

Active: 448Idle: 0

Compute$43.01/hr

Compute usage over time

Code with AI

## Your coding agent can manage the database too

Agents already write the queries. With Xata they can also create the branch to run them on.

In your editor

### Works with the agents you already use

- Claude Code
- Cursor
- Codex

Create a branch, run a migration, read the schema and throw the branch away, all from Claude Code, Cursor, Codex, VS Code (Copilot), Windsurf, Cline, OpenCode or Zed.

- [Agent guides](/docs/ai-agents/claude-code)

MCP server

### One hosted endpoint for every client

Connect with OAuth or an API key. Read, write and destructive calls are separate tools, and SQL is read-only by default.

Connect from Claude Code

- [Connect MCP](/docs/platform/mcp)

Branching workflows

## One branch per pull request, preview or CI run

### [One branch per pull request](/solutions/pull-request)

[Test every migration before it merges.](/solutions/pull-request)

[Learn more](/solutions/pull-request)

### [One branch per preview](/solutions/preview)

[Production-shaped data behind every preview deployment.](/solutions/preview)

[Learn more](/solutions/preview)

### [One branch per CI/CD run](/solutions/ci-cd)

[A clean database for every test run.](/solutions/ci-cd)

[Learn more](/solutions/ci-cd)

Get started

## Let your agent set it up

Paste one prompt into your coding agent and it walks you through the setup, asking before it creates anything billable.

1. 01

   ### Install the CLI

   Your agent asks first, then installs it.

2. 02

   ### Log in

   Sign in through the browser, or use a scoped API key in CI.

3. 03

   ### Create a project and branch

   The agent proposes the settings and asks before creating anything billable.

4. 04

   ### Connect your app

   Credentials go into a gitignored env file, never into the chat.

### [Agent onboarding guide](/docs/ai-agents/onboarding)

[The prompt and the steps your agent follows to set up Xata.](/docs/ai-agents/onboarding)

[Read the guide](/docs/ai-agents/onboarding)

### [Quickstart prompt](/docs/quickstart)

[Paste one prompt into your coding agent and start from there.](/docs/quickstart)

[Get the prompt](/docs/quickstart)

## Give every agent task its own Postgres

Create a database when the task starts, delete it when it ends.

[Get started](https://console.xata.io/signup)[Talk to an engineer](https://cal.com/team/xata/xata-sales)
