|
| 1 | +--- |
| 2 | +title: "Your AI Agent Needs a Database. Give It One in Five Seconds" |
| 3 | +slug: "give-your-agent-a-database" |
| 4 | +date: "2026-07-09" |
| 5 | +authors: |
| 6 | + - "Nurul Sundarani" |
| 7 | +metaTitle: "npx create-db: Instant Postgres for Your Coding Agent" |
| 8 | +metaDescription: "npx create-db gives coding agents a temporary Postgres database in seconds, no sign-up. JSON output lets Cursor, Claude Code, and Codex test on real Postgres." |
| 9 | +heroImagePath: "/give-your-agent-a-database/imgs/hero.svg" |
| 10 | +heroImageAlt: "A terminal running npx create-db --json and returning a Postgres connection string" |
| 11 | +metaImagePath: "/give-your-agent-a-database/imgs/meta.png" |
| 12 | +tags: |
| 13 | + - "ai" |
| 14 | + - "prisma-postgres" |
| 15 | +--- |
| 16 | + |
| 17 | +The fastest way to give a coding agent a database is one command: `npx create-db@latest`. It provisions a temporary [Prisma Postgres](https://www.prisma.io/docs/postgres) database, a managed serverless PostgreSQL instance, in a few seconds, with no sign-up and nothing to install. Add the `--json` flag and the output becomes machine-readable, so Cursor, Claude Code, Codex, or any other agent can provision a database and start testing without a human in the loop. |
| 18 | + |
| 19 | +The database deletes itself after 24 hours. If the work turns out to matter, one click on the claim URL keeps it permanently, for free. This post covers how `create-db` works, how it compares to Docker, SQLite, and mocks, and how to wire it into your agent's workflow. |
| 20 | + |
| 21 | +## What is npx create-db? |
| 22 | + |
| 23 | +[`create-db`](https://www.prisma.io/docs/postgres/npx-create-db) is an open-source CLI that provisions temporary Prisma Postgres databases with a single command. Each database runs real PostgreSQL, requires no account, lives for 24 hours by default, and can be claimed into a permanent instance via a URL in the output. It runs anywhere Node.js 16 or later runs. |
| 24 | + |
| 25 | +```bash |
| 26 | +npx create-db@latest |
| 27 | +``` |
| 28 | + |
| 29 | +A few seconds later: |
| 30 | + |
| 31 | +``` |
| 32 | +┌ 🚀 Creating a Prisma Postgres database |
| 33 | +│ |
| 34 | +│ Provisioning a temporary database... |
| 35 | +│ It will be automatically deleted in 24 hours, but you can claim it. |
| 36 | +◇ Database created successfully! |
| 37 | +│ |
| 38 | +● Database Connection |
| 39 | +│ Connection String: |
| 40 | +│ postgres://<username>:<password>@db.prisma.io:5432/postgres?sslmode=require |
| 41 | +│ |
| 42 | +◆ Claim your database → |
| 43 | +│ Keep your database for free: |
| 44 | +│ https://create-db.prisma.io?projectID=proj_... |
| 45 | +└ |
| 46 | +``` |
| 47 | + |
| 48 | +There is also a [web interface](https://create-db.prisma.io/) with a schema editor and Prisma Studio built in, if you would rather click than type. |
| 49 | + |
| 50 | +## Why coding agents need ephemeral databases |
| 51 | + |
| 52 | +When you build by hand, you provision a database once and reuse it for weeks. Agents work differently. They spin up throwaway projects, test a migration in isolation, reproduce a bug from a fresh state, or run five variations of a feature in parallel. Each task wants its own clean database, immediately, and every conventional way of getting one fights the agent: |
| 53 | + |
| 54 | +- **Mocks** hide the bugs that only real SQL surfaces. |
| 55 | +- **SQLite** accepts queries that production Postgres rejects, and vice versa. |
| 56 | +- **Docker** needs a running daemon, an image pull, and port juggling, and many agent sandboxes cannot run containers at all. |
| 57 | +- **A shared dev database** turns parallel agents into test failures nobody can reproduce. |
| 58 | + |
| 59 | +Setup time compounds the problem. An agent that generates a working prototype in three minutes but waits ten for database provisioning has lost the loop. We saw the same pattern when [Claude generated 50 websites overnight](/claude-generated-50-websites-overnight-prisma-compute): the bottleneck is rarely code generation, it is everything around it. |
| 60 | + |
| 61 | +## How create-db compares to Docker, SQLite, and mocks |
| 62 | + |
| 63 | +| | `npx create-db` | Docker Postgres | SQLite | Mocks | |
| 64 | +| --- | --- | --- | --- | --- | |
| 65 | +| Real PostgreSQL engine | ✅ | ✅ | ❌ | ❌ | |
| 66 | +| Works without a daemon or install | ✅ | ❌ | ✅ | ✅ | |
| 67 | +| Runs in restricted agent sandboxes | ✅ | ❌ | ✅ | ✅ | |
| 68 | +| Non-interactive, parseable output | ✅ (`--json`) | Manual scripting | n/a | n/a | |
| 69 | +| Cleans up automatically | ✅ (24 h) | ❌ | ❌ | n/a | |
| 70 | +| Can graduate to production | ✅ (claim) | ❌ | ❌ | ❌ | |
| 71 | + |
| 72 | +The short version: SQLite and mocks are fast but do not test what you ship, Docker tests what you ship but agents struggle to run it unattended, and `create-db` gives you real Postgres with none of the setup. |
| 73 | + |
| 74 | +## How an agent provisions a database with `--json` |
| 75 | + |
| 76 | +Terminal output with box-drawing characters is for humans. The `--json` flag prints structured output and exits, with no prompts and no spinners: |
| 77 | + |
| 78 | +```bash |
| 79 | +npx create-db@latest --json |
| 80 | +``` |
| 81 | + |
| 82 | +```json |
| 83 | +{ |
| 84 | + "success": true, |
| 85 | + "connectionString": "postgres://<username>:<password>@db.prisma.io:5432/postgres?sslmode=require", |
| 86 | + "claimUrl": "https://create-db.prisma.io/claim?projectID=proj_...", |
| 87 | + "deletionDate": "2026-07-10T08:22:23.812Z", |
| 88 | + "region": "ap-southeast-1", |
| 89 | + "name": "2026-07-09T08:22:21.803Z", |
| 90 | + "projectId": "proj_..." |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +The agent's loop is three steps: |
| 95 | + |
| 96 | +1. Run `npx create-db@latest --json` and parse the output. |
| 97 | +2. Set `DATABASE_URL` to `connectionString` and run migrations, seeds, and tests against it. |
| 98 | +3. When the task ends, do nothing. The database deletes itself at `deletionDate`. If the work should be kept, surface `claimUrl` to the human. |
| 99 | + |
| 100 | +You can pin a region with `--region` (`ap-southeast-1`, `ap-northeast-1`, `eu-central-1`, `eu-west-3`, `us-east-1`, or `us-west-1`) or pick one interactively with `-i`. The [create-db docs](https://www.prisma.io/docs/postgres/npx-create-db) list every flag. |
| 101 | + |
| 102 | +## What agents use it for |
| 103 | + |
| 104 | +### Testing migrations before they touch anything real |
| 105 | + |
| 106 | +Schema changes are the riskiest edits an agent makes. With a disposable database, the agent applies the migration to a fresh instance, runs the test suite against it, and only then proposes the change. If the migration is destructive or wrong, the blast radius is a database that was going to delete itself anyway. |
| 107 | + |
| 108 | +### Reproducing bugs on real Postgres |
| 109 | + |
| 110 | +"Works with mocks, fails in production" usually means the mock lied. An ephemeral Prisma Postgres instance lets the agent reproduce the bug against the same engine, the same SQL dialect, and the same constraint behavior you run in production, without borrowing your staging environment. |
| 111 | + |
| 112 | +### Integration tests without Docker |
| 113 | + |
| 114 | +CI-style integration tests normally mean maintaining a `docker-compose.yml` and hoping the runner has a working daemon. `npx create-db --json` replaces that with a single command that works anywhere Node.js runs, including environments where agents cannot run containers at all. |
| 115 | + |
| 116 | +### One database per task, branch, or agent |
| 117 | + |
| 118 | +Agents parallelize. Five agents sharing one dev database trample each other's state. Giving each task its own database costs one command, and every run starts from a known-clean state. |
| 119 | + |
| 120 | +### Prototypes that graduate |
| 121 | + |
| 122 | +Most agent-built prototypes get thrown away, and with `create-db` the database disappears with them. When a prototype turns into the real thing, you do not rebuild: claim the database and it becomes a permanent Prisma Postgres instance with your data intact. |
| 123 | + |
| 124 | +## Teach your agent to reach for it |
| 125 | + |
| 126 | +Agents use the tools they are told about. Add a few lines to your `CLAUDE.md`, Cursor rules, or `AGENTS.md`: |
| 127 | + |
| 128 | +```markdown |
| 129 | +When you need a database for testing or prototyping, run: |
| 130 | + |
| 131 | + npx create-db@latest --json |
| 132 | + |
| 133 | +Parse the JSON output and use `connectionString` as `DATABASE_URL`. |
| 134 | +The database is temporary and deletes itself after 24 hours. |
| 135 | +If the work should be kept, show me the `claimUrl` so I can claim the database. |
| 136 | +``` |
| 137 | + |
| 138 | +If your agent speaks MCP, the [Prisma MCP server](https://www.prisma.io/docs/ai/tools/mcp-server) goes further: it can provision databases, run SQL, introspect schemas, and [search the Prisma docs](/search-prisma-docs-from-your-coding-agent) through one endpoint. `create-db` is the zero-config entry point; the MCP server is the full toolbox. |
| 139 | + |
| 140 | +## The trade-offs |
| 141 | + |
| 142 | +`create-db` is deliberately scoped, and it is worth knowing the edges: |
| 143 | + |
| 144 | +- **24-hour lifetime.** Unclaimed databases are deleted, data included. That is the point for scratch work, but do not put anything in one that you would miss. The `deletionDate` field tells you exactly when the clock runs out. |
| 145 | +- **Temporary means temporary.** Until claimed, treat the database as a scratch environment, not a home for real user data. |
| 146 | +- **Fixed region set.** Six regions are available today. Pick the closest one with `--region` if latency matters for your test. |
| 147 | + |
| 148 | +None of these bite in the intended use case, and the claim flow covers the moment a throwaway database stops being throwaway. |
| 149 | + |
| 150 | +## Frequently asked questions |
| 151 | + |
| 152 | +<Accordions type="single"> |
| 153 | + <Accordion title="What is npx create-db?"> |
| 154 | +`create-db` is an open-source CLI that provisions a temporary [Prisma Postgres](https://www.prisma.io/docs/postgres) database with one command, `npx create-db@latest`. No account is required, the database lives for 24 hours by default, and a claim URL in the output converts it into a permanent instance for free. |
| 155 | + </Accordion> |
| 156 | + <Accordion title="How long does a create-db database last?"> |
| 157 | +24 hours from creation. After that the database and its data are deleted automatically. The exact timestamp is shown in the CLI output and returned as `deletionDate` in `--json` mode. Claiming the database before that time removes the expiry. |
| 158 | + </Accordion> |
| 159 | + <Accordion title="How does an AI agent use create-db without human input?"> |
| 160 | +Run `npx create-db@latest --json`. The command prints a JSON object with `connectionString`, `claimUrl`, `deletionDate`, `region`, and `projectId`, then exits without any interactive prompts. The agent parses `connectionString` into `DATABASE_URL` and proceeds. This works in Claude Code, Cursor, Codex, and any environment that can run Node.js 16 or later. |
| 161 | + </Accordion> |
| 162 | + <Accordion title="Is npx create-db free, and can I keep the database?"> |
| 163 | +Yes. Creating temporary databases costs nothing and requires no account. To keep one, open the claim URL from the output, sign in to the [Prisma Console](https://console.prisma.io/), and claim it into a workspace with capacity for a new project. The claimed database keeps its data and stops expiring. |
| 164 | + </Accordion> |
| 165 | +</Accordions> |
| 166 | + |
| 167 | +## Try it |
| 168 | + |
| 169 | +You are one command away from seeing it work: |
| 170 | + |
| 171 | +```bash |
| 172 | +npx create-db@latest --json |
| 173 | +``` |
| 174 | + |
| 175 | +Run it, hand the connection string to your agent, and let it test against real Postgres. If the result is worth keeping, claim the database and keep building on it. The [create-db documentation](https://www.prisma.io/docs/postgres/npx-create-db) covers the CLI options, the web interface, and the claim flow in detail. |
| 176 | + |
| 177 | +To stay up-to-date about everything that's happening in the Prismaverse, keep an eye on our [changelog](https://www.prisma.io/changelog) and [follow us on X](https://pris.ly/x)! And if you have ideas for how Prisma can be improved, always feel free to open an issue on [GitHub](https://github.com/prisma/prisma) or reach out to us on [Discord](https://pris.ly/discord). |
0 commit comments