Building

Environment variables

How .env works: the values SpinBuild manages, the ones you add, and what the model can and cannot see.

Updated 2 Nov 2026

Every project has a .env file at its root. SpinBuild generates it, keeps parts of it up to date, and keeps its secrets out of the model's view.

What SpinBuild manages

Two variables are written and refreshed by SpinBuild whenever the preview starts:

VariableValue
DATABASE_URLThe connection string for the project's private Postgres database
PORTThe port the dev server listens on inside the preview

Don't edit these; they're overwritten on the next start. The header comment in the file says the same.

A project with no .env yet, or no DATABASE_URL in it, can get one straight away with Initialize database. It is in the builder's file list and under Project settings → Database. See Database.

What you add

Everything else is yours. Add API keys and configuration the normal way:

STRIPE_SECRET_KEY=sk_live_…
NEXT_PUBLIC_APP_NAME=Acme CRM

Save the file (the editor's Save button) and restart the preview for the running app to pick the new values up. Variables prefixed NEXT_PUBLIC_ are exposed to the browser, as in any Next.js app; everything else is server-only.

What the model sees

The model needs to know which variables exist to write correct code, but it must never see secret values. So:

  • Variable names are visible to the model.
  • The values of managed secrets (DATABASE_URL) are shown to it as <managed-by-qyant>.
  • When the model changes .env (adding a new variable, say), the real values are restored before the file is written. Developers write it by accepting the diff. People who don't write code have it written as the change lands.

The model can — and often will — add variables it needs. For example, if you ask for email sending it may add RESEND_API_KEY= to .env and tell you to fill it in.

AI assistants connected over MCP are stricter. They see the variable names in .env with every value shown as <hidden>, and they cannot write or delete .env. They list the variables an app needs in .env.example, and they set DATABASE_URL with the initialize_my_project_database tool.

GitHub and deployments

.env is never pushed to GitHub, never included in source downloads, and never baked into a deployment image. Deployments receive their configuration as container environment variables at start: DATABASE_URL is injected automatically; variables you added in .env are carried over from the project so the deployed app behaves like the preview. Rotate a secret by editing .env and redeploying.

Reading variables in code

Standard Next.js:

// server code only
const key = process.env.STRIPE_SECRET_KEY;

// available in the browser too
const name = process.env.NEXT_PUBLIC_APP_NAME;