Vibe Coding with Replit -- May 7, 2026

How to Use Environment Variables in Replit to Keep My Keys Safe

By Arjita SethiMay 7, 20265 min read
Direct Answer

Store API keys and sensitive information in Replit Secrets (environment variables) by opening the padlock icon in the Replit sidebar, creating a secret with a name like STRIPE_SECRET_KEY, and pasting the value. Reference it in your code as process.env.STRIPE_SECRET_KEY. Never paste API keys directly in code files -- Replit code is visible to anyone with access to your project. Secrets are encrypted and only available to your running app.

What You Are Actually Building

The goal is to store API keys and secrets safely. When this is done, you will have a secure setup where your API keys are stored as environment variables, not exposed in your code. Non-technical builders complete this in Replit using Claude to write all the code — you describe what you want, Claude builds it, you test it and describe any fixes.

Environment variables let you store sensitive information like API keys without putting them in your code. Here is exactly how they work in Replit.

What You Need First

You do not need to write any code. Claude handles all of it. Your job is to describe outcomes clearly and test what gets built.

How to Describe It to Claude

The most common mistake non-technical builders make is describing what they want at too high a level. "Add a database" is not specific enough. Claude needs to know: what data will be stored, what triggers the storage, who can access it, and what the data should look like when displayed back.

Start with the outcome, not the feature. Instead of "I need authentication," say "I need users to enter their email address, receive a six-digit verification code, and use that code to access a protected page at /dashboard."

Once Claude builds the first version, test it yourself. If something is wrong, describe the problem in plain language — what you expected to happen versus what actually happened. Claude fixes it. Repeat until it works correctly.

What the Working Version Looks Like

A correctly built version will have a secure setup where your API keys are stored as environment variables, not exposed in your code. Run through the full user flow yourself before considering it done: create a test account, submit a test form, or make a test payment depending on what you built. If something breaks during your test, that is normal — paste the error message into Claude and describe what you were trying to do.

Common Mistakes and How to Fix Them

Frequently Asked Questions

How do I use environment variables in Replit?
Open the padlock icon (Secrets) in the Replit sidebar, create a new secret with a clear name (STRIPE_SECRET_KEY), paste the value, and reference it in code as process.env.STRIPE_SECRET_KEY.
Why should I use Replit Secrets instead of putting keys in my code?
Replit code files are visible to anyone with project access. Secrets are encrypted and only available to your running app. API keys pasted in code files are exposed to everyone who can see the project.
Can I use environment variables for database connection strings too?
Yes -- any sensitive configuration value goes in Secrets. Database URLs, passwords, connection strings, OAuth credentials, all of it.
How does Claude know to use environment variables?
Claude automatically uses process.env.KEY_NAME convention when writing code that requires API keys or sensitive configuration. If you see a key value directly in Claude-generated code, ask it to replace with the environment variable reference.
What happens to my Secrets when I fork or share a Replit project?
Secrets are not shared when a project is forked or shared. The person receiving the fork gets the code but not the secret values. They need to add their own keys. This is the correct behavior.
Build With AI

Build Secure Apps From Day One

The Vibe Coding track at Build with AI covers security best practices for non-technical builders.

Start Your 7-Day Free Trial