A Ralph Wiggum Loop implementation that works™

📚 Full docs: ralphloop.sh
Ralph is a long-running AI agent loop. Ralph automates software development tasks by iteratively working through a task list until completion. This allows for long running agent loops, effectively enabling AI to code for days at a time.
This is an implementation that actually works, containing a hackable script so you can configure it to your env and favorite agentic AI CLI. It's set up by default to use Claude Code in Docker Sandboxes, and supports multiple Docker Sandboxes agents.
👉 Watch the video for an in-depth walkthrough.
- Getting Started
- (Optional) Set up code base
- 1️⃣ Step 1: Install Ralph
- 2️⃣ Step 2: Create a PRD + task list
- 3️⃣ Step 3: Set up the agent inside Docker Sandboxes
- 4️⃣ Step 4: Run Ralph
- Running the Ralph Loop with custom options
- (Optional) Adjusting to your language/framework
- How It Works
- How Is This Different from Other Ralphs?
- Steering the Agent
- Support
- Structure
- Continued Development
- Skills
- Available Skills
- Skills Directory Structure
- Reference
- Docker Sandboxes
- Playwright configuration
- Vitest configuration
- Running with a different agentic CLI
- Starting from scratch
- Debugging
- How to inspect the sandbox and debug
- Allowing network access
- Authentication issues in Sandboxes / Login not persisting
- License
Getting Started
(Optional) Set up code base
I recommend using a CLI to bootstrap your project with the necessary tools and dependencies, e.g.:
# for a Tanstack app:
npx @tanstack/cli create lib --add-ons eslint,form,tanstack-query,nitro --no-git
# or for a Next.js app
npx create-next-app@latest my-app --typescript --tailwind --eslint --app
If you must start from a blank slate, which is not recommended, see Starting from scratch. You can also go for a more barebone start by running npx create-vite@latest src --template react-ts
1️⃣ Step 1: Install Ralph
Run this in your project's directory to install Ralph.
npx @pageai/ralph-loop
Docs: ralphloop.sh
2️⃣ Step 2: Create a PRD + task list
Use the prd-creator skill to generate a PRD from your requirements.
Open up Claude Code or Cursor etc., switch to plan mode, and prompt it with your requirements. Like so:
Use the prd-creator skill to help me create a PRD and task list for the below requirements.
An app is already set up with React, Tailwind CSS and TypeScript.
Requirements:
- A SaaS product that helps users manage their finances.
- Target audience: Small business owners and freelancers.
- Core features:
- Track income and expenses.
- Create and send invoices.
- Track payments and receipts.
- Generate reports and insights.
- Connect to bank accounts and credit cards.
- Connect to accounting software.
- Connect to payment processors.
- Use the shadcn/ui library for components.
- Integrate with Stripe for payments.
- Use Supabase for database.
- You can find env variables in the .env.example file: SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, STRIPE_SECRET_KEY, etc. are available in the runtime.
// etc.
Check out the video for a more realistic example on how to write requirements.
✨ Pro tips
- mention libraries and frameworks you want to use
- mention env variables, e.g. for DB, 3rd party API keys, etc. Store them in
.env and add it to .gitignore
- describe user flows and journeys
- add relevant docs and UI references if applicable inside
/docs and mention them in the requirements
- be as descriptive as possible
- it's fine to write in your own language
Then, follow the Skill's instructions and verify the PRD and then tasks.
It is highly recommended that you review individual task requirements before starting the loop. Review EACH TASK INDIVIDUALLY.
3️⃣ Step 3: Set up the agent inside Docker Sandboxes
Install and sign in to Docker Sandboxes first. See Docker's AI overview and Docker Sandboxes docs for the official setup flow.
Authenticate your chosen Docker Sandboxes agent before running Ralph. Claude is the default:
./ralph.sh --login
Ralph prints all supported login commands, then opens the selected agent inside the correctly named sandbox. To log in to a different supported agent, pass --agent:
./ralph.sh --login --agent codex
Follow the instructions to log in to that agent. Ralph names sandboxes as ralph-<agent>-<current-dir>-<hash8>, for example ralph-claude-my-app-a1b2c3d4. To print the exact sandbox name without starting the loop, run:
./ralph.sh --print-name
./ralph.sh --print-name --agent cursor
Once the sandbox exists (after the first --login or after Ralph runs at least once), publish your dev server port to the host with ./ralph.sh --ports. The port is captured from the dev-server URL you set during install and stored in RALPH_DEFAULT_PORTS in ralph.sh:
./ralph.sh --ports
./ralph.sh --ports --agent codex
👉 Answer "Yes" to Bypass Permissions mode, that's the exact reason why you are using the Docker sandbox.
Alternative: API keys — you can configure API keys for supported agents instead of interactive login, but this is usually more expensive and not recommended. See Docker's supported agents docs for per-agent setup details.
If you want to use a different agentic CLI, see Running with a different agentic CLI.
4️⃣ Step 4: Run Ralph
./ralph.sh -n 50 # Run Ralph Loop with 50 iterations
✍️ Note: the first iteration will be spent on ensuring the named sandbox environment is set up correctly. Expect 5 minutes to complete.
Running the Ralph Loop with custom options
# Run the agent loop (default: 10 iterations)
./ralph.sh
# Run with custom iteration limit
./ralph.sh 5
./ralph.sh -n 5
./ralph.sh --max-iterations 5
# Run exactly one iteration
./ralph.sh --once
# Run with a different supported agent
./ralph.sh --agent codex
./ralph.sh -a cursor -n 5
# Log in to an agent inside Ralph's deterministic sandbox
./ralph.sh --login
./ralph.sh --login --agent cursor
# Publish the configured dev port to the selected agent sandbox
./ralph.sh --ports
./ralph.sh --ports --agent codex
# Print the deterministic sandbox name
./ralph.sh --print-name
./ralph.sh --print-name --agent codex
# Pass extra options to the selected agent
./ralph.sh --agent codex -- --model gpt-5.5
./ralph.sh -a gemini -- --model pro
# Show help
./ralph.sh --help
NB: you might need to run chmod +x ralph.sh to make the script executable.
The default "mode" is "implementation". Depending on your use case, you might want to change .agent/PROMPT.md to a different mode, e.g. "refactor", "review", "test" etc.
⚠️ If you want to use a different language or testing framework, see below.
(Optional) Adjusting to your language/framework
This script assumes the following are installed:
If you'd like to use a different language, testing framework etc. please adjust .agent/PROMPT.md to reflect your setup, server ports and startup commands etc.
👉 The loop is controlled by this prompt, which will be sent to the agent each iteration.
How It Works
Each iteration, Ralph will:
- Find the highest-priority incomplete task from
.agent/tasks.json
- Work through the task steps defined in
.agent/tasks/TASK-{ID}.json
- Run tests, linting, and type checking
- Complete task, take screenshot, update task status and commit changes
- Repeat until all tasks pass or max iterations reached
How Is This Different from Other Ralphs?
This was kept hackable so you can make it your own.
The script follows the original concepts of the Ralph Wiggum Loop, working with fresh contexts and providing clear verifiable feedback.
It also works generically with any task set.
✨ Features
- PRD generation - Creates a PRD and task list from requirements
- Task lookup table generation - Creates a task lookup table from the PRD
- Task breakdown + step generation - Breaks down each task into manageable steps
- Iteration tracking - Shows progress through iterations with timing
- Stream preview - Shows live output from the Agent
- Step detection - Identifies current activity (Thinking, Implementing, Testing, etc.)
- Screenshot capture - Captures a screenshot of the current screen
- Notifications - Alerts when human input is needed
- History logging - Saves clean output from each iteration
- Timing - Shows timing metrics for each iteration and total time
- Steering - Allows prioritizing critical work that needs to be done before the loop can continue
Besides that:
- it allows you to dump unstructured requirements and have the agent create a PRD and task list for you.
- it uses a task lookup table with individual detailed steps → more scalable as you get 100s of tasks done.
- it's sandboxed and more secure
- it shows progress and stats so you can keep an eye on what's been done
- it instructs the agent to write and run automated tests and screenshots per task
- it provides observability and traceability of the agent's work, showing a stream of output and capturing full historical logs per iteration
Steering the Agent
In some cases, you might notice the agent is having trouble, slowed down or struggling to overcome a blocker.
While the loop is running, you can edit the .agent/STEERING.md file to add critical work that needs to be done before the loop can continue.
The agent will check this file each iteration and if it finds any critical work, it will skip tasks and complete the critical work first.
Support
The ralph.sh script is designed to be hackable.
It is configured to use Claude Code in Docker Sandboxes by default, and you can select another supported agent with --agent.