Agent harness
Harness Runtime runs agent harnesses, like OpenCode or Claude Code, for you. Each session is one agent in its own sandbox: you send it a turn, it works with its tools and files, and it replies. An environment config says which harness a session runs and what it may do; a template adds your tools to the sandbox image; a trigger starts a session on a schedule or a webhook.
- harness
- opencode
Declare an environment
Section titled “Declare an environment”import * as DigitalOcean from "@alchemy.run/digitalocean";
export const MyEnv = DigitalOcean.Agents.EnvironmentConfig("MyEnv", { manifest: { apiVersion: "agents.digitalocean.com/v1alpha1", kind: "Agent", spec: { runtime: { adapter: "opencode" } }, },});The manifest is Harness Runtime’s own format. An environment config can’t change once created, so a new manifest creates a new config and deletes the old one.
Start sessions from a runtime
Section titled “Start sessions from a runtime”CreateSession gives a runtime a client for sessions of one environment. Harness Runtime has no API to create a narrower token, so pass a token with the agents scopes; it reaches the runtime as a secret.
import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Config from "effect/Config";import * as Effect from "effect/Effect";import * as HttpServerResponse from "effect/http/HttpServerResponse";import { MyEnv } from "./agents.ts";
export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { const token = yield* Config.Redacted("AGENTS_TOKEN"); const sessions = yield* DigitalOcean.Agents.CreateSession(MyEnv, { token }); return { fetch: Effect.gen(function* () { const session = yield* sessions.create(); const runId = yield* session.send("Write a README for this repository."); return HttpServerResponse.json({ sessionId: session.sessionId, runId }); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(DigitalOcean.Agents.CreateSessionHttp)),) {}A session lives until you delete it. sessions.get(id) returns a handle to one you started earlier.
Work with a session
Section titled “Work with a session”A session handle runs commands in the sandbox, checkpoints it, and copies it:
yield* session.exec(["git", "status"]);const checkpointId = yield* session.checkpoint("before-refactor");const [copy] = yield* session.fork({ fromCheckpointId: checkpointId });yield* session.resolve(requestId, "approve");yield* session.delete;fork starts up to four new sessions from a checkpoint, or from the session’s state now. resolve answers a request the agent made for approval. pause and resume stop and restart the sandbox, keeping its state.
Add your tools
Section titled “Add your tools”A template builds a sandbox image from one of DigitalOcean’s base templates plus your image, which must be Debian- or Ubuntu-based:
yield* DigitalOcean.Agents.Template("Tools", { baseTemplate: "coding-claude-code", image: "ghcr.io/acme/agent-tools:1.4.0",});Run on a schedule
Section titled “Run on a schedule”A trigger starts a session at each cron time and sends it a prompt:
yield* DigitalOcean.Agents.Trigger("Standup", { cron: { expression: "0 9 * * 1-5", timeZone: "America/New_York" }, prompt: "Summarize yesterday's merged pull requests.", session: { apiVersion: "agents.digitalocean.com/v1alpha1", kind: "Agent", spec: { runtime: { adapter: "opencode" }, permissions: { defaultAction: "allow" } }, }, output: { mode: "email", email: "team@example.com" },});No one answers approval requests in a scheduled session, so give it permissions up front.
Limits
Section titled “Limits”- Workspaces, shared files across sessions, are in preview and enabled per team.
- Sessions you start at run time aren’t in the Stack: delete them yourself.
See Action Gateway for the tools agents call.