Create a Custom Agent Box
Create the box withagent.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:
| 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.custom-anthropic-agent.mjs
Update an Existing Custom Agent
You can update the custom agent command for an existing custom box: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
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.