Custom agents let you bring your own agent process to an Upstash Box. The box still provides the same sandbox, filesystem, shell, git, logs, streaming, and console experience, but your code decides how to call the model and how to produce output.
Use a custom agent when the built-in Claude Code, Codex, OpenCode, or Cursor agents do not fit your workflow.
Create a Custom Agent Box#
Create the box with agent.harness: Agent.Custom and provide a customHarness command. The command runs inside the box for every box.agent.run() or box.agent.stream() call.
Agent Contract#
For each run, Box executes your command and appends these arguments:
--session is only included when a prior session exists.
Your process must write Server-Sent Events to stdout using the box-sse-v1 protocol:
Supported event names:
| Event | Description |
|---|---|
text | Adds text to the visible response |
thinking | Emits reasoning/thinking text |
tool | Shows a tool call in logs |
tool_result | Shows a tool result in logs |
done | Finishes the run successfully |
error | Finishes the run with an error |
SDK Helper#
If your custom agent process can import @upstash/box, use runCustomHarness() to parse Box arguments and emit the protocol events:
Minimal Anthropic Agent#
This custom agent calls Anthropic directly and streams text back through Box.
Write the custom agent into the box before the first run:
Update an Existing Custom Agent#
You can update the custom agent command for an existing custom box:
This only works for boxes created with agent.harness: Agent.Custom.
Custom Harness Examples#
Ready-to-run examples for popular open-source agents:
- Pi — multi-provider coding agent
- Gemini — Google Gemini via
@google/genai - Aider — git-aware code editor
- Goose — autonomous coding agent
- CrewAI — multi-agent orchestration framework
- Pydantic AI — type-safe agent framework
Notes#
- Custom agents do not use managed provider keys.
- Pass secrets through
envonBox.create()or configure them inside the box. - The command must be a binary name from
PATHor an absolute path under/workspace/home/or/home/boxuser/. - The command runs as
boxuserinside the existing box sandbox.