@remotehost/sdk
v2.0.0
Published
Official TypeScript SDK for RemoteHost
Maintainers
Readme
RemoteHost TypeScript SDK
The official server-side TypeScript SDK for the RemoteHost API, licensed under Apache-2.0.
Source, issues, and contributions: remotehostai/sdk.
The low-level request and response types in src/generated are generated from
the published public spec, contracts/openapi/dist/remotehost.json: the TS
API's contracts/openapi/base/openapi.json plus the contracts/openapi documents
listed in contracts/openapi/published.yaml. The public resource API is
maintained by hand in the rest of src.
Install
npm install @remotehost/sdkUsage
import RemoteHost from "@remotehost/sdk";
const remotehost = new RemoteHost({
apiKey: process.env.REMOTEHOST_API_KEY,
orgId: "org_123",
});
const sandbox = await remotehost.sandboxes.create({
projectId: "project_123",
agent: "codex",
});
console.log(sandbox.id, sandbox.status);
const result = await sandbox.commands.run("pnpm test");
const source = await sandbox.files.readText("src/index.ts");
const preview = await sandbox.previews.create({ port: 3000 });
await sandbox.sleep();apiKey defaults to REMOTEHOST_API_KEY in server environments. Browser use
is rejected by default to prevent accidentally exposing a secret key. Sandbox
creation waits until the sandbox is running and the agent inside it answers,
so the first command works; pass waitForReady: false to get the
provisioning response immediately.
An organization's work is split into workspaces, each internal or
external for good; projects live in one. A project's environments are
durable work (a disk, checkpoints, a git branch) that a sandbox attaches to,
and each boots from one of the project's environment templates:
const workspaces = await remotehost.workspaces.list();
const [template] = await remotehost.environmentTemplates.list({ projectId: "project_123" });
const environment = await remotehost.environments.create({
projectId: "project_123",
name: "feature-x",
environmentTemplateId: template?.id,
});
const { sandbox: attached } = await remotehost.environments.attach(environment.id, {
projectId: "project_123",
});
await remotehost.environments.detach(environment.id, { projectId: "project_123" });remotehost.workspaces answers 404 until the workspace API is enabled for the
deployment.
A Session is one person's work on one host, and the processes that run in it outlive the call that started them: start one, go away, come back to it.
const session = await remotehost.sessions.create({
workspaceId: "ws_123",
host: { kind: "sandbox", id: sandbox.id },
label: "ship the checkout fix",
});
const dev = await session.processes.start({
kind: "backend",
argv: ["pnpm", "dev"],
cwd: "/code/app",
ports: [3000],
});
// The API holds the request until the condition is true, so nothing polls.
await dev.wait({ port: 3000 }, { timeoutMs: 120_000 });
for await (const event of dev.attach({ fromOffset: 0 })) {
if (event.type === "output") process.stdout.write(event.data);
if (event.type === "exited") break;
}
await dev.send("rs\n");
await dev.kill();attach is resumed by byte offset: with fromOffset it carries on from
exactly that byte, so an agent that comes back reads what it missed and
nothing else, and a connection that drops is opened again behind the iterator
from the offset it reached. It needs a WebSocket: Node 22 and browsers have
one, and on Node 20 pass webSocket. Sessions are a person's own: an API key
is refused 403 people_only.
API failures throw RemoteHostAPIError with status, code (for example
rate_limited or limit_reached), requestId, and the response body.
For endpoints without a convenience resource, use the fully typed
remotehost.raw OpenAPI client. Generated paths, operations, and
components types are available from @remotehost/sdk/openapi.
See the SDK guide for commands, files, previews, metrics, lifecycle methods, errors, retries, and cancellation.
Sync client
@remotehost/sdk/sync keeps a local copy of a workspace's backends (issues, the
Atlas tracker's issues, teams and states) and syncs it live over sync protocol
v1. Writes show at once and settle when the service answers; a refused write
disappears and its write() resolves refused. Stores: indexedDbStore() in a
browser (one leader tab owns the socket), memoryStore() for scripts, and
sqliteStore() from @remotehost/sdk/sync/sqlite on Node 22.13 or later.
import { createSyncClient, issues, type IssuesIssue, type IssuesState } from "@remotehost/sdk/sync";
import { sqliteStore } from "@remotehost/sdk/sync/sqlite";
const sync = createSyncClient({
url: "wss://sync-staging.remotehost.ai/v1/connect",
workspace: workspaceId,
token: async () => ({ token: await mintSyncToken() }), // POST /v1/auth/sync-token
store: sqliteStore({ path: "./replica.db" }),
backends: ["issues"],
});
await sync.start(); // resolves once caught up
const rows = sync.records<IssuesIssue>("issues", "issue");
rows.subscribe((change) => console.log(change.kind, change.confirmed));
// A new issue in the first state's team; the service numbers it.
const todo = sync.records<IssuesState>("issues", "state").all()[0];
if (!todo) throw new Error("the workspace has no states yet");
const issue = issues.putIssue({
identifier: "",
number: 0,
title: "Ship the launch",
state_id: todo.id,
team_id: todo.team_id,
});
const [outcome] = await sync.write(issue);
console.log(outcome?.status, await sync.pending());
await sync.stop();Development
The public repository is a standalone source mirror maintained from RemoteHost's monorepo. Clone it to inspect the implementation, run tests, or contribute a fix:
git clone https://github.com/remotehostai/sdk.git
cd sdk
npm ci
npm test
npm run typecheck
npm run buildThe generated API types are checked in, so building does not require access to
the API server or the monorepo. Do not edit src/generated/schema.ts by hand;
report contract changes in an issue so they can be regenerated upstream.
Public pull requests are welcome. Maintainers integrate changes into the
monorepo and synchronize them back here. Published versions have matching
v<version> tags and GitHub releases; main may contain an unpublished snapshot.
See CONTRIBUTING.md.
For development inside the monorepo:
pnpm --filter @remotehost/sdk generate
pnpm --filter @remotehost/sdk test
pnpm --filter @remotehost/sdk buildLicense
Apache License, Version 2.0, from the version after 1.0.0; NOTICE holds the copyright line. 1.0.0, already published, remains under MIT. Dependencies retain their own licenses; see THIRD-PARTY-NOTICES.md.
