# Rivet and OpenOrange

> Let your agent do it: Back my Rivet Actor's agent harness with Hermitbox. Install `hermitbox` beside the harness, set `HERMITBOX_API_URL` and `HERMITBOX_API_KEY` on the runner and nowhere else, never in a response or this chat, and use the page's `hermitboxProvider()` factory as the harness's sandbox provider, keeping its existing hooks. For an OpenOrange Sandbox binding, tell me first that the published release can't select Hermitbox without the prepared patch the page links. Follow the exact steps in https://docs.hermitbox.dev/v0.3.2/integrations/rivet.md.

Run a Rivet Actor's agent harness on Hermitbox sandboxes, and keep the harness's own hooks. The
TypeScript SDK exports `hermitboxProvider` from `hermitbox/provider`, which implements Rivet's
published `SandboxProvider` contract. An OpenOrange Sandbox binding can use the same provider
once a [prepared patch](#openorange-sandbox-binding) is applied.

Install the SDK alongside your existing adapter, and set `HERMITBOX_API_URL` and
`HERMITBOX_API_KEY` in the actor runner's environment. The key stays there: it never belongs in a
Worker response or a sandbox environment.

## Agent harness in a Rivet Actor

1. Install `hermitbox` alongside your harness.
2. Set the install's `HERMITBOX_API_URL` and `HERMITBOX_API_KEY` on the runner.
3. Use this factory for the harness's sandbox provider. Keep its existing `create`/`connect`,
   `suspend` and `destroy` hooks; the Actor stores the sandbox id as before.

```ts
import { hermitboxProvider } from 'hermitbox/provider'

export const sandboxProvider = hermitboxProvider()
```

`bun examples/rivet-provider.ts` runs the complete lifecycle example, with no model key. The
provider holds no per-Actor state.

What each hook does:

- `create` returns an id.
- `connect` starts stopped compute or wakes a sleeping sandbox. On a deleted or expired sandbox it
  returns `undefined`; authentication, placement and transport failures throw.
- `suspend` puts the sandbox to sleep with its data kept.
- `destroy` deletes it.

On a missing sandbox, `suspend` and `destroy` do nothing. Mutations are sent once.

## OpenOrange sandbox binding

OpenOrange 1.0.2 has a closed list of provider names and no API to register a custom provider, so
an unmodified release can't select Hermitbox. The [prepared patch](https://docs.hermitbox.dev/v0.3.2/upstream/open-orange.md)
adds that registration; it isn't part of the published OpenOrange package. With the patch applied:

1. Install `hermitbox` next to OpenOrange.
2. Set `HERMITBOX_API_URL`, `HERMITBOX_API_KEY` and `ORANGE_SANDBOX_PROVIDER=hermitbox` on the runner.
3. The provider registration below backs the existing Sandbox binding; Worker code keeps
   its existing `getSandbox()` calls. The prepared patch supplies the native file/preview bridge.

```ts
import { hermitboxProvider, hermitboxPortAddress } from 'hermitbox/provider'

export const sandboxProvider = hermitboxProvider()
export const portAddress = (id: string, port: number) =>
  hermitboxPortAddress(id, port)
```

### Files and options

The binding works in the connected sandbox's persistent directory: `/data` on mounted tiers, or
the agent's data directory on the process tier. Native file paths must stay inside that root.

The host's default tier applies. A caller can pass `{ tier, template, require }` to the factory,
with optional `url` and `key` overrides. The provider doesn't pass `require` to the API: it refuses
every nonempty `require` with `missing_guarantee` and the names, before creation, so no
requirement is silently dropped. Unavailable tiers and templates keep the API's reason.

With no template named, container creation uses the project's configured `repoImage`. A template
used with this provider must mount its persistent storage at `/data` on mounted tiers. Use
`sandbox.cwd` to resolve file paths and execution directories. The provider learns the process
directory when connecting and leaves the optional provider-level `cwd` unset.

### Commands

Exec accepts an absolute `cwd`, an explicit environment, a millisecond timeout and an
AbortSignal. An undefined or zero timeout adds no provider deadline; the install's execution
ceiling still applies.

- A timeout kills the process group and returns `timedOut: true` and `exitCode: null`.
- An abort kills it and rejects with `Error('aborted')`, including an abort during process
  startup.
- `onData` receives stdout and stderr as they arrive; final output keeps the streams separate.
- Nonzero exits are results.
- Output above the SDK's capture budget throws `output_truncated`.
- A lost connection keeps the SDK's unknown-outcome error and never replays the command.

### Previews

`hermitboxPortAddress(id, port)` publishes a port through Hermitbox's own edge and returns its
preview URL. It never returns a sandbox IP or a direct host listener, and capacity and host
policy refusals stay visible. The prepared binding patch sends preview requests through that
address.

### What stays unsupported

OpenOrange's other partial and unsupported methods behave as its
[Sandbox binding](https://raw.githubusercontent.com/rivet-dev/open-orange/1cabf2e9db300361c9f0b751c7723da7eb706f5e/docs/modules/sandbox.mdx)
documents: its session/code-context methods throw, inactivity timeout does nothing, container
images and custom entrypoints are not run, and PTY/stdin, interception, container snapshots and
inspection are unsupported. Full `Files.stat/lstat` metadata isn't available through this bridge.

## Browser rendering

Hermitbox's browser can't serve as OpenOrange's Browser Rendering endpoint, and no persistent
browser compatibility is claimed. OpenOrange reads one `ORANGE_BROWSER_CDP_URL`, opens a new
connection to it for each launch, and has no callback to refresh it. Its [Browser Rendering
rules](https://raw.githubusercontent.com/rivet-dev/open-orange/1cabf2e9db300361c9f0b751c7723da7eb706f5e/docs/modules/browser-rendering.mdx)
need a URL that accepts each new connection.

Hermitbox's browser access is short-lived. `box.browser()` mints a capability URL that
expires within five minutes. Minting another rotates access, and sleep or recreation also
invalidates old access. Don't put a minted Hermitbox browser URL in `ORANGE_BROWSER_CDP_URL`; use
the browser through Hermitbox's own SDK.

## Pinned interfaces

sandbox-adapter **0.5.6**, Apache-2.0, from the integrity-pinned npm package; OpenOrange
**1.0.2**, Apache-2.0, commit `1cabf2e9db300361c9f0b751c7723da7eb706f5e`.

The published adapter declares abort as `Error('aborted')`, timeout as a null exit and a flag,
and missing connections as undefined. Its Docker provider stops and restarts on suspend and
connect; normal command failures remain results. The declarations are a development dependency
only.

## How this is tested

CI typechecks this version on every change and the newest published version weekly.
Acceptance against a real Hermitbox deployment exercises every provider method, cancellation,
streaming, sleep/wake persistence, missing connections and edge preview. Both pages' blocks and
the complete example run in the same job.
