Skip to main content
This is an optional extension of the Running Agents on Sandboxes tutorial. Complete the main tutorial first.
The starter image is used when you start a devbox without specifying an image, and as the default base when you build a blueprint without providing Dockerfile content. It includes:
  • Core tools: jq, sudo
  • Extras: dnsutils, iputils-ping, less, vim, rsync, gh
  • Python stack: Python 3.12, pip, uv
  • Node stack: Node 22.15.0, npm, Yarn 1.22.22 via corepack

Overview

Create a turn-based system where an AI agent posts status updates to a GitHub pull request and executes tasks based on PR review comments. This enables collaborative workflows where reviewers guide the agent’s work just by leaving comments.
1

Set up the initial PR and post agent status

Create a pull request and post an initial status comment from the agent. This establishes the communication channel for turn-based interaction.
2

Monitor PR comments and process agent tasks

Set up a loop that monitors the PR for new comments, processes them as agent prompts, and posts progress updates. Use the -r flag to resume the most recent Claude Code conversation across multiple PR comments.
Named Shells: We use a named shell (devbox.shell("agent-shell")) to maintain the working directory state across commands. After the initial cd ~/sample-todo-nextjs, all subsequent commands run in that directory without needing to cd each time. Learn more about named shells.Session Resumption: The -r flag without a session ID will resume the most recent Claude Code conversation. On the first call, it starts a new session, and on subsequent calls, it automatically resumes the previous conversation, maintaining context across multiple PR comments.Production Webhooks: In production, you should use GitHub webhooks to receive real-time notifications when comments are added, rather than polling. This polling approach is shown for simplicity, but webhooks are more efficient and responsive.
3

Add error handling and status updates

Enhance the workflow with better error handling and more detailed status updates to keep reviewers informed.
4

Add command filtering and special instructions

Add support for special commands and filtering to make the interaction more controlled and useful.

Best Practices

  • Use webhooks in production: Replace polling with GitHub webhooks for real-time notifications
  • Rate limiting: Be mindful of GitHub API rate limits when polling frequently; authenticating with a GitHub token or GitHub App increases your available quota
  • Error recovery: Implement retry logic for transient failures
  • Security: Validate and sanitize user input and secrets before passing them to the agent
  • Logging: Keep detailed logs of agent actions for debugging and auditing
  • Session management: Use claude -r -p "query" to resume the most recent conversation. The -r flag without a session ID automatically resumes the most recent session, maintaining context across multiple PR comments
  • Claude Code flags:
    • Use -p flag for print mode (non-interactive, SDK usage)
    • Use -r or --resume without a session ID to resume the most recent session
    • Use -r "<session-id>" or --resume "<session-id>" to resume a specific session by ID
    • Use -c to continue the most recent conversation in the current directory
    • For more production examples of webhook-based workflows and secret management, see the Runloop tutorials and Account Secrets documentation.

Next Steps