Skip to content

About

OpenHands on Render: run the OpenHands coding agent headless in Render Sandboxes, orchestrated by Render Workflows.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

openhands-render

Give it a GitHub issue and it opens a pull request. An OpenHands coding agent writes the fix in an isolated Render Sandbox, a second sandbox runs the tests, and Render Workflows ties the steps together with retries, timeouts, and fan-out.

Deploy to Render

factory_many                 one run per batch, at most N issues at a time
└── factory  #word-count     one issue, up to 3 attempts
    ├── run_agent            OpenHands in sandbox A → diff + summary
    ├── verify               tests in fresh sandbox B → pass, or failure output
    ├── run_agent            retry: prior diff + failure output
    ├── verify
    └── open_pr              push branch, open PR (workflow host only)

Note

Render Sandboxes and Render Workflows are in public beta. APIs, defaults, limits, and prices can change.

Why it matters

A coding agent runs code it wrote itself: shell commands, package installs, test suites. That code is untrusted, so it shouldn't run next to your Render API key or your GitHub token.

This template splits the work so it stays contained. Workflows tasks hold the credentials and make the decisions. Sandboxes do the work: each agent run gets a disposable microVM that can reach GitHub, its LLM provider, and package registries, and nothing else. The agent never gets a GitHub token or, by default, the LLM key. It hands back a diff, and the workflow decides whether that diff becomes a pull request.

It's small on purpose: a handful of commented Python files, no OpenHands fork, and no framework beyond the Render and OpenHands SDKs.

Built on Render

  • Sandboxes: the whole OpenHands agent loop runs headless in a sandbox, with its terminal, file editor, and task tracker tools.
  • Snapshots: the OpenHands environment is built once and snapshotted, so each run starts in seconds instead of reinstalling the SDK.
  • Egress allow-lists and credential brokering: agent sandboxes reach only GitHub, the LLM provider, and package registries, and Render injects the LLM key into requests on the way out. Verify sandboxes can't reach the LLM provider at all.
  • Workflows: each step is a task with its own instance, timeout, and retry policy. Tasks chain with ctx.run and fan out with asyncio.gather.
  • Blueprints: one render.yaml with type: workflow deploys the service and prompts for each secret.

Get running

You need:

  • A Render workspace with Sandboxes enabled, a Render API key, and your workspace ID (tea-...).
  • An LLM provider key. The default model is anthropic/claude-sonnet-5; any LiteLLM model string works. Use a key dedicated to this workload, with a spend limit at the provider.
  • A GitHub repo you own for the pull requests, and a token with Contents and Pull requests write access to it.
  • Python 3.11+ and the Render CLI 2.34+.

Important

The first run creates a sandbox-group credential for the LLM key, which needs a workspace admin. With a non-admin API key, prepare_environment fails with 403 forbidden. Have an admin run python scripts/run_local.py --build-snapshot once, or set LLM_KEY_IN_SANDBOX=true to skip brokering. In a shared workspace, also set SANDBOX_GROUP_ID to a group used only for this project, because the credential applies to every sandbox in its group.

1. Run one issue from your machine

Local runs skip Workflows: the tasks run in your process, while the agent and the tests still run in real sandboxes.

git clone https://github.com/render-examples/openhands-render && cd openhands-render
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env   # fill in the secrets and TARGET_REPO

python scripts/run_local.py --build-snapshot     # once
python scripts/run_local.py examples/issues/01-word-count-hyphens.json --agent-only

The example issues target examples/demo-app, a tiny package with a real bug. They leave repo blank on purpose, so pull requests only land where you choose. Fork this repo and set TARGET_REPO=your-org/openhands-render in .env; the target needs examples/demo-app on its main branch.

--agent-only stops after run_agent and prints the diff, the summary, and the cost, with the agent's tool calls streaming past as it works. Drop the flag to run the whole factory: verify, retry, pull request.

2. Deploy the workflow

Click Deploy to Render, or create a Blueprint from your fork. render.yaml defines one workflow service, openhands-render, and prompts for RENDER_API_KEY, RENDER_WORKSPACE_ID, GITHUB_TOKEN, LLM_API_KEY, and TARGET_REPO. On start, python -m workflows.main registers six tasks under the slug openhands-render.

3. Trigger a run

python scripts/trigger.py examples/issues/01-word-count-hyphens.json --wait
python scripts/trigger.py examples/issues/*.json --concurrency 3      # factory_many

scripts/trigger.py calls workflows.start_task("openhands-render/factory", [issue]). Follow the run, its subtasks, and their streamed sandbox logs in the Dashboard under your workflow's Runs. From any other app, start the same task with the Render API.

To develop the tasks against the local Workflows runtime instead:

render workflows dev -- python -m workflows.main
RENDER_USE_LOCAL_DEV=true python scripts/trigger.py examples/issues/01-word-count-hyphens.json

How a run flows

  1. Prepare. prepare_environment finds or builds the snapshot, named after a hash of sandbox/setup.sh and the pinned OpenHands versions. It also creates or updates the sandbox-group credential that injects LLM_API_KEY into HTTPS requests to the LLM host.
  2. Agent. run_agent creates a sandbox from the snapshot with an egress allow-list and no secrets in its environment. It copies in sandbox/runner.py and a job.json, then streams the runner's output into the task logs.
  3. Headless OpenHands. The runner clones the repo, starts an OpenHands Conversation on the checkout, sends the task, and calls run(). When the agent finishes, it writes the diff against the base commit and a summary with the status, final message, cost, and tokens. run_agent copies both out and terminates the sandbox.
  4. Verify. verify creates a fresh sandbox, clones the base branch, applies the diff, and runs the issue's verify command.
  5. Retry. If verification fails, factory runs the agent again from the previous diff, with the failure output in its prompt, up to MAX_ATTEMPTS.
  6. Pull request. When verification passes, open_pr applies the diff to a fresh clone on the workflow host, commits, force-pushes openhands/<issue-id>, and opens a pull request or updates the one already open.

docs/guide.md walks through the code for each step.

Security

Secret Workflow host Agent sandbox Verify sandbox
RENDER_API_KEY, RENDER_WORKSPACE_ID Creates and drives sandboxes Never Never
GITHUB_TOKEN Pushes branches, opens PRs (open_pr only) Never Never
LLM_API_KEY Stored as a sandbox credential, injected into requests to the LLM host Only if LLM_KEY_IN_SANDBOX=true Never
  • The LLM key stays out of the sandbox. Render sets the auth header on requests to the LLM host, so the agent's environment has no key to read. MAX_BUDGET_USD caps each attempt's spend through OpenHands. Set LLM_KEY_IN_SANDBOX=true only if brokering can't cover your provider or isn't available in your workspace; the tasks never fall back on their own.
  • The agent can't push. It has no GitHub credentials, so it can clone public repos and nothing more. For a private repo, set "private": true on the issue: the host clones it with its token and copies in a checkout that holds no credentials.
  • Egress is an allow-list. Agent sandboxes reach GitHub, the LLM provider's API host, PyPI, and npm. Add more with EXTRA_EGRESS_HOSTS.
  • Verification is out of the agent's reach. Tests run in a separate sandbox from a clean checkout plus the diff. The agent can't edit the verify command or see that sandbox, but it can change the tests themselves, so review test changes in the PR.
  • The host never runs repository code. open_pr uses git apply, which only writes files and refuses paths outside the repo. Commit hooks are skipped, and the token reaches git through an environment-scoped header, never a URL or .git/config.
  • CI changes are refused by default. Changes under .github/workflows/ or .github/actions/ can run with your repository's secrets once merged, or as soon as the PR opens for some triggers. open_pr refuses them unless ALLOW_WORKFLOW_CHANGES=true. A fine-grained token without the Workflows permission enforces the same thing on GitHub's side.
  • Sandboxes always end. Each sandbox is terminated when its task finishes and has a hard timeout_seconds in case the task crashes first.

Read the residual risks before pointing it at private code.

Issue format

{
  "repo": "your-org/your-repo",
  "base": "main",
  "workdir": "examples/demo-app",
  "id": "word-count-hyphens",
  "title": "word_count splits hyphenated words and contractions",
  "task": "Plain-language description of the change, as you'd write it for a teammate.",
  "verify": "python3.12 -m venv /tmp/venv && /tmp/venv/bin/pip install -q -e '.[test]' && /tmp/venv/bin/pytest -q",
  "private": false
}

Only title and task are required.

  • repo is the GitHub owner/name (or a github.com URL) the pull request lands on. It defaults to TARGET_REPO; the run fails with a clear error if neither is set.
  • id names the branch (openhands/<id>) and defaults to a slug of title.
  • verify runs from workdir with a timeout. Leave it empty to skip verification and open the PR as soon as the agent finishes.

Configuration

Variable Default What it does
RENDER_API_KEY (required) Creates and drives sandboxes from the workflow host
RENDER_WORKSPACE_ID (required) The workspace sandboxes are created in
GITHUB_TOKEN (required) Used by open_pr only
LLM_API_KEY (required) Brokered onto LLM requests; never enters a sandbox by default
TARGET_REPO (none) Default owner/name when an issue has no repo field
LLM_MODEL anthropic/claude-sonnet-5 Any LiteLLM model string; also picks the LLM egress host and auth header
LLM_BASE_URL (none) A gateway or proxy; becomes the only LLM host allowed, with Authorization: Bearer
LLM_KEY_IN_SANDBOX false Fallback: put LLM_API_KEY in the agent sandbox env
SANDBOX_PLAN 2c-4g 1c-2g, 2c-4g, 4c-8g, or 8c-16g
SANDBOX_IMAGE (none) Start from an image built from sandbox/Dockerfile instead of the snapshot
SANDBOX_GROUP_ID (default group) Pin sandboxes and the LLM credential to this group
MAX_ATTEMPTS 3 Agent attempts per issue
MAX_ITERATIONS 100 OpenHands steps per attempt
MAX_BUDGET_USD 3.0 OpenHands LLM spend cap per attempt
AGENT_SANDBOX_TIMEOUT_SECONDS 3600 Hard lifetime of an agent sandbox
VERIFY_SANDBOX_TIMEOUT_SECONDS 1200 Hard lifetime of a verify sandbox
EXTRA_EGRESS_HOSTS (none) Comma-separated hosts to add to the allow-lists
ALLOW_WORKFLOW_CHANGES false Let open_pr push changes under .github/workflows/ and .github/actions/

Cost and limits

Each step logs one JSON line, and factory returns the totals:

{"event": "cost", "step": "run_agent", "issue": "word-count-hyphens", "llm_usd": 0.061788, "sandbox_usd_max": 0.002558, "sandbox_seconds": 29.1, "status": "finished"}

Measured on a live workspace in November 2026, with anthropic/claude-sonnet-5 and 2c-4g sandboxes:

Run Wall time LLM Sandboxes (upper bound)
Build the snapshot (once) 26 s $0 < $0.01
factory, one example issue 43 s $0.06 $0.003
factory where verify fails once and the retry passes 100 s $0.06 $0.007
factory_many, four issues, concurrency 4 89 s $0.22 total $0.015 total

The example issues are small on purpose; a real issue on a real codebase takes more turns and costs more.

  • LLM is usually most of the bill. The worst case per issue is about MAX_ATTEMPTS × MAX_BUDGET_USD.
  • Sandboxes are billed at the published beta prices: CPU per CPU-hour of actual use, memory per GB-hour provisioned. sandbox_usd_max assumes full CPU use, so it's an upper bound.
  • Workflows are billed per task run, by compute plan and duration. The tasks mostly wait on sandboxes, so the default plan is enough.
  • Limits: sandboxes run in Oregon only. A Workflows task runs at most 24 hours. Snapshot captures are rate-limited to 10 a minute, which is one reason the snapshot is built once and not per run.

Repository layout

Path What it does
render.yaml The workflow service Blueprint
workflows/tasks.py prepare_environment, run_agent, verify, open_pr, factory, factory_many
workflows/config.py Settings, egress allow-lists, and prices. Start here to tune it.
workflows/sandbox.py Create, exec, copy, and terminate helpers, and the snapshot cache
workflows/credentials.py The sandbox-group credential that injects the LLM key
workflows/github.py Branch push and pull request, on the host
workflows/issues.py The issue format and its validation
sandbox/setup.sh Installs Python 3.12 and the OpenHands SDK; the snapshot is built from it
sandbox/runner.py One headless OpenHands run, inside the sandbox
sandbox/Dockerfile The same environment as an image, if you'd rather import one
scripts/ run_local.py runs one issue without deploying; trigger.py starts runs through the Render API
examples/ Sample issues and the demo package they target

Develop

pip install -r requirements-dev.txt
pytest                                  # no Render, GitHub, or LLM credentials needed
ruff check . && ruff format --check .

The tests cover the issue format, egress lists, credential setup, cost math, the factory's retry and fan-out logic, the GitHub push and PR calls, and the runner against local git repos. tests/test_openhands_sdk.py also runs runner.py end to end with the real OpenHands SDK and a scripted local LLM; it needs Python 3.12+ and pip install -r sandbox/requirements.txt, and skips otherwise.

Learn more

License

MIT. See LICENSE.

About

OpenHands on Render: run the OpenHands coding agent headless in Render Sandboxes, orchestrated by Render Workflows.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages