feat(sdk): spawnFleetSandbox, /fleet and /attach subpaths, sandbox readonlyPaths
Summary
This PR implements the workforce#338 upstream contract (issue #1765), with D4 resolved as option 1: spawnFleetSandbox starts a running agent.
@agent-relay/sdk/fleet→spawnFleetSandbox(input). It provisions a Cloud fleet sandbox and starts the agent harness through placement, waiting for confirmation by default. It then requires the engine's dispatch receipt (dispatchedNodeId/handlerNodeId) to prove the agent landed on the ensured sandbox node. If no receipt proves it, or a receipt names another node, the call releases the agent, deletes an owned sandbox, and throwsplacement_mismatch. Caller hooks (verifySandbox,resolveWorkerCwd,resolveTask) andpersistRelaycastTargetmay be async; they are awaited inside the cleanup boundary. The launcher client andattach()both use the transport pinned at spawn. It returns aFleetSandboxHandle:- fields:
sandboxId,nodeId,nodeName,agentName,ownsSandbox, the redactedsandbox, andinvocation; attach({ mode }): a live terminal through a private local socket;destroy(): idempotent; releases the agent, then deletes the sandbox only when this call provisioned it.
- fields:
- One path.
agent-relay fleet spawn --sandboxnow callsspawnFleetSandbox, passing its repo inference, cwd and task context as hooks and its dependencies for injection. The CLI and SDK cannot drift. All existing sandbox regression tests pass unchanged. @agent-relay/sdk/attach/@agent-relay/cloud/attach:startFleetNodeAttachProxywithsocketPath,finishedandclose(), plus single-agent discovery fromnodeId.readonlyPaths: forwarded in the sandbox ensure request (also via--sandbox-readonly-path). Cloud enforcement: AgentWorkforce/cloud#4303.- A caller-declared
sandboxIdis retained: failure cleanup anddestroy()never delete it. A non-emptyenvis rejected (unsupported_env) rather than silently dropped, because fleet spawn cannot deliver a per-agent environment yet.
Merge of main
Main was merged in. Main's newer attach changes (relay#1829 decoded repaint, terminal-session replacement) and workspace-transport changes (fallbackBaseUrl, DEV Relaycast route) were ported into the modules this PR moved to @agent-relay/cloud. persistWorkspaceRelaycastTarget moved to @agent-relay/cloud/workspace-transport, and the CLI re-exports it.
Consumer note (workforce#338)
- Import from
@agent-relay/sdk/fleetand@agent-relay/sdk/attach, not the@agent-relay/cloud/*paths the draft probes. - Prefer
handle.attach(): it carries the verified Relaycast target.startFleetNodeAttachProxy({ node: handle.nodeName, agent: handle.agentName })also works. - Pass
namefor the agent;label,permissionsandauthModeare not part of the contract. - An empty
readonlyPathslist is ignored.
Live proof (production)
These runs used this branch's spawnFleetSandbox against production Cloud on agent37 (E2B) sandboxes:
- Before cloud#4303 deployed (red):
readonlyPathswas ignored. The mount token keptfs:write, the read-only file was mode 644, an append exited 0, and the server content changed. - After the deploy (green): the mount token's write grant is narrowed to the writable roots. The read-only file is mode 444 and an append is denied. A direct Relayfile API write returns 403. The server content is unchanged, and writes to the normal path still succeed.
- Details: https://github.com/AgentWorkforce/cloud/pull/4303#issuecomment-6070839084
Local verification (CI does not run on trunk PRs)
Head 5ec40ec9a (trunk merged in). Inherited RELAY_*/AGENT_RELAY* variables were removed for the test runs.
| Command | Result |
|---|---|
npx npm@10.9.4 ci --ignore-scripts (CI's npm) | ok |
npm run build | exit 0 |
npm run typecheck | exit 0 |
npm run lint | 0 errors (103 warnings, all pre-existing) |
(cd packages/sdk && npm test) | 15 files, 197 passed |
(cd packages/cloud && npm test) | 24 files (1 skipped), 522 passed, 4 skipped |
npx vitest run packages/cli/ --maxWorkers=4 | 96 files (1 skipped), 1,995 passed, 15 skipped |
Validation
- Red → green:
packages/sdk/src/__tests__/fleet-spawn.test.ts(7 tests) failed beforespawnFleetSandboxexisted. The new CLI test "rejects an agent that lands on another node and tears the sandbox down" fails on the previous CLI and passes now. - SDK suite: 197 passed. Cloud package: 521 passed. CLI: 1,993–1,995 passed (15 skipped). All runs had inherited
RELAY_*andAGENT_RELAY*variables removed. - Two CLI tests are timing-sensitive on a loaded machine and flake intermittently:
broker-lifecycle"keeps the claim when the spawn rejects…" (a file this PR doesn't touch);attach-fleet-node"uses the terminal-session request timeout…". Main's own original CLI attach module fails this one in 4 of 5 isolated runs here, so it is pre-existing.
Both pass on re-run.
- Every review-bot finding was fixed with a regression test that failed before the fix; the replies on each thread name the test.
npm run buildandnpm run typecheckpass; lint reports 0 errors.- Live read-only enforcement proof on E2B: see AgentWorkforce/cloud#4303 and the comment below.
Release: RELEASE NEEDED
v13.2.0 was cut before this PR merged and does not contain it. @agent-relay/sdk gains the ./fleet and ./attach exports and an exact dependency on @agent-relay/cloud (13.2.0). The CHANGELOG is marked [Unreleased - Minor]. workforce#338 needs the next minor release of @agent-relay/sdk and @agent-relay/cloud after this merges.
RelayFlow Proof
- Change type:
feature - RelayFlow case:
sandbox-readonly-paths
The generated base/head probe checks exact request forwarding and the compiled CLI help. Server-side enforcement is proven live in AgentWorkforce/cloud#4303.
🤖 Generated with Claude Code
[!NOTE]
Medium Risk
Touches Cloud sandbox provisioning, placement verification, and terminal attach—critical fleet paths—but behavior is heavily tested and failures fail closed with cleanup.
Overview
Introduces spawnFleetSandbox on @agent-relay/sdk/fleet as the single orchestration path for Cloud fleet sandboxes: ensure sandbox, pin Relaycast transport, spawn and confirm the harness, fail closed when the dispatch receipt does not prove the agent landed on the sandbox node, and return a handle with attach() (private stdio socket) and idempotent destroy(). agent-relay fleet spawn --sandbox now delegates to that function so CLI and SDK stay aligned.
Shared Cloud modules are published and re-exported: @agent-relay/cloud/attach (fleet terminal attach; CLI’s large loopback adapter becomes a re-export), @agent-relay/cloud/fleet, and @agent-relay/cloud/workspace-transport. SDK adds matching ./fleet and ./attach entries and depends on @agent-relay/cloud.
Read-only Relayfile mounts: readonlyPaths on ensure (validated /path/** subtrees) plus --sandbox-readonly-path on fleet spawn; requests are forwarded to Cloud for server-side enforcement.
CI/eval builds now compile session, config, and cloud before the SDK; changelog and docs describe the new APIs.
Reviewed by Cursor Bugbot for commit 8a7e5683e7fd6c1427e9579bf6ce531e780e6bc2. Bugbot is set up for automated code reviews on this repo. Configure here.
Agent Relay sessions
claudesession2b09cf4d· contributor · rangh prcommands · last active 2026-10-10