afterbuild/ops
ERR-682/stack trace
ERR-682
Replit Agent Code Won't Run Outside Replit? Here's the Escape Plan

Replit Agent Code Won't Run Outside Replit? Here's the Escape Plan

Last updated 15 April 2026 · 10 min read · By Hyder Shah
Direct answer

Replit Agent code almost never runs outside Replit on the first try. It depends on auto-injected Secrets, Nix-provided binaries, Replit Database / Object Storage, and hardcoded ports / paths the Agent never mentions. To escape you have to identify each dependency, replace it with a portable equivalent, and freeze the result with a Dockerfile. Plan a week; most lock-ins are resolvable.

Quick fix for Replit Agent Code Won't Run Outside

Start here

Export the code and bring it local

In the Repl, connect a GitHub repo (Version Control → Connect to GitHub). Push all branches. Clone locally. Run npm install, pnpm install, or pip install -r requirements.txt.

Do not try to run the app yet. First, list every dependency the Agent installed — check package.json, requirements.txt, and replit.nix (if present). The Nix file reveals non-npm binaries the Agent assumed would exist.

Deeper fixes when the quick fix fails

  1. 02

    Replace Replit Secrets with a .env file

    In the Repl’s Secrets tab, copy every key-value pair into a local .env. Add dotenv (Node) or python-dotenv at the top of your entrypoint so process.env still resolves the same names.

    // Node
    import "dotenv/config";
    
    # Python
    from dotenv import load_dotenv
    load_dotenv()

    Add .env to .gitignore. Never commit it.

  2. 03

    Swap Replit Database for Redis or Postgres

    Search the code for @replit/database or replit.Database. Every call is a key/value read or write. Swap for Upstash Redis (if pure key/value) or a Postgres table with key text primary key, value jsonb (if you want ACID).

    Write a one-off migration script that iterates the old Replit Database and writes each pair to the new store. Run it once, archive the output.

  3. 04

    Swap Replit Object Storage for S3 or R2

    Search for @replit/object-storage. Replace with the standard AWS SDK (@aws-sdk/client-s3). Any S3-compatible endpoint works — Cloudflare R2 has no egress fees and is the easiest drop-in.

    Migrate the files with rclone copy replit:bucket r2:bucket. Keep the original bucket read-only for a month as a rollback.

  4. 05

    Freeze everything in a Dockerfile

    Open replit.nix. Every package listed there needs an equivalent in your Dockerfile base image. Convert like so:

    FROM node:20-slim
    RUN apt-get update && apt-get install -y \
        ffmpeg imagemagick postgresql-client \
        && rm -rf /var/lib/apt/lists/*
    WORKDIR /app
    COPY package*.json ./
    RUN npm ci --production
    COPY . .
    EXPOSE 3000
    CMD ["node", "index.js"]

    Test locally with docker build and docker run. If it runs in Docker, it runs on any host: Fly, Railway, Render, AWS ECS, Google Cloud Run.

  5. 06

    Deploy to a real host and cut DNS

    Recommended targets by workload:

    • Stateless API: Google Cloud Run, Fly, Railway, Render
    • Websockets / queues: Fly, Railway (Reserved VM equivalent)
    • Static SPA: Vercel, Netlify, Cloudflare Pages

    Set up health checks, staging / prod environments, and a rollback plan. Point DNS only after running both old and new in parallel for a day.

Once Docker runs the app, the Agent’s workspace magic is permanently defanged. From there you can refactor, add tests, and bring in a real team without Replit standing in the way.

Why AI-built apps hit Replit Agent Code Won't Run Outside

Replit is deliberately opinionated. The workspace gives the Agent a rich environment: Nix packages available on $PATH, Secrets pre-wired into process.env, a built-in Replit Database (key/value) that needs zero config, and an Object Storage service accessed via a Replit-specific client. Agent output reaches for those APIs because they are the fastest way to ship inside Replit.

That convenience is the lock-in. Pull the code out and you discover: “GitHub export is one way only. Not so great if you want to bounce between tools.”— a real complaint from Replit users trying to escape. The code runs nowhere until you replace the hidden Replit APIs with standard ones.

You're stuck tweaking via GitHub or living with what the AI hands you.
Replit user, Indie Hackers

Diagnose Replit Agent Code Won't Run Outside by failure mode

Clone the Repl locally, run npm install (or the Python equivalent), and try to start the app. The first error tells you which category of lock-in to tackle first.

Error when you run locallyLock-in categoryReplacement
process.env.X is undefinedReplit Secrets auto-injectionAdd a .env file + dotenv
command not found: ffmpeg / imagemagick / psqlNix-provided binariesInstall via Dockerfile apt-get / brew
Cannot find module '@replit/database'Replit Database (key/value)Switch to Redis or Postgres
Cannot find module '@replit/object-storage'Replit Object StorageSwitch to S3 / Cloudflare R2
EADDRINUSE or blank pageHardcoded port 3000 or missing PORT envRead process.env.PORT with a fallback
ENOENT on /home/runner/...Hardcoded Replit pathsUse __dirname / relative paths

Related errors we fix

Still stuck with Replit Agent Code Won't Run Outside?

Emergency triage · $299 · 48h turnaround
We restore service and write the root-cause report.

If you need off Replit this sprint, a fixed-price migration beats another Agent loop:

  • You want to own your code and infrastructure
  • You have paying users and can't afford downtime
  • You've tried to export but the code won't start locally
  • You're planning to hire a real engineering team
start the triage →

Replit Agent Code Won't Run Outside questions

Why won't my Replit Agent code run anywhere else?+
Replit Agent leans on workspace conveniences that do not exist outside Replit: auto-injected Secrets, Nix-provided CLI tools on PATH, the Replit Database key/value API, Replit Object Storage, and hardcoded paths under /home/runner. Pull the code out and every one of those breaks silently. You have to replace them with portable equivalents — .env, Docker-installed binaries, Redis or Postgres, S3-compatible storage, and relative paths.
Can I move a Replit Agent app to AWS, GCP, or a VPS?+
Yes, and it is usually a 3-5 day job for a developer who knows both sides. The workflow is: export via GitHub, swap Replit-specific APIs for standard ones (Redis, S3, .env), freeze the runtime in a Dockerfile, and deploy. Google Cloud Run and Fly are the easiest targets because they accept a Dockerfile directly. AWS ECS works once you add a task definition.
Is Replit GitHub export enough to escape lock-in?+
No. GitHub export gives you the source code but not the runtime. The app still depends on Replit Secrets, the Nix shell, and any Replit-specific modules the Agent imported. Exporting is step one of six — you still have to strip the runtime lock-in before the code runs anywhere else. Users frequently note the export is one-way only.
How long does it take to migrate off Replit?+
A typical Replit Agent app takes 3-7 days of focused engineering: 1 day to inventory the Replit-specific APIs, 1-2 days to swap them for portable equivalents, 1 day to write a Dockerfile and confirm local runs, 1-2 days to deploy to the new host with monitoring and env setup. Databases and object storage add time if you have real production data to move.
What does it cost to migrate a Replit Agent app off the platform?+
Fixed-price migrations start around $2,000 for a simple stateless API and run to $8,000 for a full-stack app with database, object storage, and zero-downtime cutover. Freelance hourly rates are $50-$150 with most projects in the 20-60 hour range. Our App Migration service quotes within 24 hours of a diagnostic call.
Should I rewrite the Replit code or migrate it?+
Migrate first, rewrite later. Getting the Agent's code running on portable infrastructure proves it works and preserves your users. Once you are off Replit, you can refactor at leisure with tests, code review, and normal git workflow. Rewriting before escape doubles the risk: you lose both the working app and the deadline.
Next step

Ship the fix. Keep the fix.

Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.

About the author

Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.

Replit Agent Code Won't Run Outside experts

If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.

Sources