Few things in modern cloud development are as jarring as the "it worked in preview, but crashed in production" trap. On Replit, this is almost always caused by one specific architectural boundary: your interactive workspace secrets and your live deployment secrets do not live in the same place.
At 365Finds, we evaluate developer platforms through practical production realities, not just editor convenience. Replit's separation between development sandboxes and production deployments is deliberate. It protects your infrastructure from accidental schema wipes and credential leaks, but it catches teams off guard when they assume a workspace secret automatically powers their live site.
Here is exactly how custom environment variables and secrets work in Replit deployments, how to configure them properly, and how to avoid leaking private keys into browser bundles.
1. Development Secrets vs. Deployment Secrets: The Vital Separation
When building inside Replit, your project operates in two distinct phases:
- Workspace (Development): The interactive cloud IDE where you code, debug, and run live previews. Variables configured here are loaded into your dev container.
- Deployments (Production): An isolated, single-tenant cloud instance hosted on Google Cloud Platform (GCP). When you publish an app (via Autoscale, Reserved VM, or Scheduled jobs), Replit spins up an independent production runtime.
Updating a secret in your workspace's Tools > Secrets panel does not automatically update a live deployment. If you change a third-party API token or a database connection string in the editor, your running production deployment will continue using the old value—or fail completely if the key was never seeded into production.
At 365Finds, we strongly endorse this decoupling. You should never point your local development server at a production PostgreSQL database, nor should a sandbox developer have automatic access to production Stripe secret keys. The friction of configuring them separately is the exact safeguard that prevents catastrophic data overwrites.
2. Step-by-Step: Configuring Deployment Secrets and Variables
Step 1: Manage Development Credentials in Workspace Secrets
Before deploying, establish your baseline keys in the development workspace:
- Open your project in the Replit Workspace.
- In the left sidebar or the Tools menu, select Secrets (the padlock icon).
- Replit splits this interface into two categories:
- Secrets: Encrypted with AES-256 at rest and TLS in transit. Use this for sensitive credentials (
DATABASE_URL,OPENAI_API_KEY,SESSION_SECRET). - Configurations: Plaintext environment settings that do not require encryption (
PORT,LOG_LEVEL,DEBUG).
- Secrets: Encrypted with AES-256 at rest and TLS in transit. Use this for sensitive credentials (
- Enter the
KeyandValuepairs, then click Add Secret or Add Configuration.
Step 2: Configure Production Environment Variables in the Publishing Tool
When you are ready to publish:
- Click the Publish button in the top-right corner of the workspace, or open Tools > Publishing under Replit Cloud.
- Select your deployment architecture (Autoscale for dynamic web traffic, Reserved VM for continuous background services and bots, or Scheduled for cron-like jobs).
- Navigate to the deployment configuration settings (under Adjust settings or Settings > Environment Variables / Secrets).
- Review the environment keys:
- By default, Replit can seed deployment variables from your workspace secrets during initial setup.
- Explicitly replace development values with production-grade credentials (e.g., swapping a dev SQLite or Neon staging branch for your production PostgreSQL connection string).
- Set environment flags such as
NODE_ENV=productionorENVIRONMENT=production.
Step 3: Trigger a Fresh Deployment (Republish)
Saving variables in the deployment settings does not hot-reload a live application. Replit applications run inside immutable container snapshots.
To inject your newly defined variables into runtime memory:
- Click Publish (or Deploy changes).
- Wait for the build and deployment pipeline to complete.
- Check the Deployment Logs tab in the Publishing interface to confirm that the application booted without environment variable errors.
3. How Runtime Code Reads Injected Variables
Replit injects both workspace and deployment variables directly into standard system environment variables at container launch. You do not need Replit-specific SDKs to read them.
Node.js / TypeScript
const apiKey = process.env.OPENAI_API_KEY;
const dbUrl = process.env.DATABASE_URL;
if (!apiKey) {
throw new Error("Missing OPENAI_API_KEY environment variable.");
}
Python
import os
api_key = os.getenv("OPENAI_API_KEY")
db_url = os.environ.get("DATABASE_URL")
if not api_key:
raise RuntimeError("Missing OPENAI_API_KEY environment variable.")
Go
package main
import (
"log"
"os"
)
func main() {
apiKey := os.Getenv("OPENAI_API_KEY")
if apiKey == "" {
log.Fatal("Missing OPENAI_API_KEY environment variable")
}
}
4. Four Critical Gotchas You Must Watch For
1. Static Deployments Do Not Support Secrets
If you select Static Deployment (used for plain HTML, CSS, and client-side JavaScript), Replit disables secrets entirely. Static deployments do not execute backend Node or Python runtimes; they are served directly from cloud storage buckets via CDN. If your application requires private API tokens or database access, you must use Autoscale or Reserved VM.
2. Client-Side Framework Leakage
In modern full-stack frameworks (Next.js, Vite, Create React App), environment variables prefixed with public markers are compiled directly into client-side JavaScript bundles:
NEXT_PUBLIC_(Next.js)VITE_(Vite)
Any variable using these prefixes is publicly visible to anyone opening browser DevTools. Never store private API secret keys, database credentials, or payment processor private keys in variables with these prefixes. Keep real secrets strictly backend-only.
3. Never Store Secrets in a Committed .env File
While local development workflows on desktop machines often rely on .env files, doing this inside Replit is risky. If your Repl is public, any file placed in the workspace filesystem is visible to other users. Always use Replit's native Secrets manager rather than checking .env files into source control.
4. Enterprise Vaults via OIDC
For organizations requiring centralized key management, Replit supports OpenID Connect (OIDC). Instead of manually entering API keys into Replit's UI, your deployment can exchange temporary cryptographic identity tokens with AWS Secrets Manager, HashiCorp Vault, Azure Key Vault, or Infisical. At 365Finds, we recommend OIDC workflows whenever compliance standards require automated key rotation.
5. 365Finds Take and Deployment Checklist
Replit's dual-tier secret architecture initially creates confusion for newcomers who expect automatic synchronization. However, treating deployment environments as distinct from development is the correct production discipline.
Before you consider your deployment live, run through this five-point verification:
- Scope Check: Did you configure credentials inside the Publishing settings, or only inside the workspace Secrets tool?
- Production Values: Does
DATABASE_URLpoint to your live managed cluster rather than a local SQLite file or dev branch? - Prefix Audit: Are sensitive backend secrets free from client-side bundle prefixes like
NEXT_PUBLIC_orVITE_? - Build Snapshot: Did you click Publish after editing variables to rebuild the container image?
- Log Inspection: Did you verify container startup logs in the Publishing console to ensure no missing-variable exceptions were thrown?
Once your production credentials are saved in the Publishing settings and the app is republished, Replit securely isolates the runtime environment.