AgentClient is the low-level raw transport for talking to agentd through a running sandbox’s relay socket. For most applications, use Sandbox, exec, and fs instead. Reach for this API when you are building protocol-level tools or higher-level SDK helpers.
All request and response bodies are raw CBOR bytes. The SDK handles framing and correlation ids, but it does not encode or decode the CBOR message body for you: decode it with a library such as cbor-x. The raw body is the full CBOR-encoded protocol Message body (v, t, p), not just the inner payload.
Typical flow
Constants
FLAG_TERMINAL
FLAG_SESSION_START
FLAG_SHUTDOWN
Static methods
AgentClient.connectSandbox()
Example
Example
core.ready handshake. Sandbox names are limited to 128 UTF-8 bytes.
Parameters
namestringSandbox name, up to 128 UTF-8 bytes.
Optional connect settings, e.g. handshake timeout.
Returns
Connected client.
AgentClient.connect()
Example
Example
agentd relay socket by path. Use this when you already have the socket path, for example one returned by socketPath().
Parameters
pathstringFilesystem path of the relay socket.
Optional connect settings, e.g. handshake timeout.
Returns
Connected client.
AgentClient.socketPath()
Example
Example
agentd relay socket path without connecting. Returns the same path connectSandbox() would dial, so you can talk to agentd over a raw byte transport (for example a transparent relay that splices bytes to and from the socket) instead of this frame client. The sandbox need not be running. Sandbox names are limited to 128 UTF-8 bytes.
Parameters
namestringSandbox name, up to 128 UTF-8 bytes.
Returns
string
Relay socket path.
Instance methods
client.request()
Example
Example
FsRequest to FsResponse).
Parameters
flagsnumberFrame flag byte, e.g.
FLAG_SESSION_START.bodyBufferCBOR-encoded protocol message body.
Returns
The single response frame.
client.stream()
Example
Example
AgentStream carries the protocol correlation id (pass it to send() for follow-up frames) and is also an async iterator of raw frames.
Parameters
flagsnumberFrame flag byte for the opening frame, e.g.
FLAG_SESSION_START.bodyBufferCBOR-encoded protocol message body.
Returns
Open stream of raw frames.
client.send()
Example
Example
id of the AgentStream returned by stream().
Parameters
idnumberCorrelation id of an open session.
flagsnumberFrame flag byte.
bodyBufferCBOR-encoded protocol message body.
client.readyBytes()
Example
Example
core.ready frame body as CBOR bytes. Captured during connect, so this is a synchronous accessor with no protocol traffic.
Returns
Buffer
CBOR-encoded
core.ready frame body.client.close()
Example
Example
Types
AgentClient
Low-level client for talking toagentd through the sandbox relay socket. All bodies are raw CBOR bytes: encode and decode them in your code with a library like cbor-x, and build typed convenience methods on top of this class. Construct it with one of the static connect methods.
| Property / Method | Type | Description |
|---|---|---|
| AgentClient.connectSandbox(name, opts?) | Promise<AgentClient> | Connect by sandbox name |
| AgentClient.connect(path, opts?) | Promise<AgentClient> | Connect by relay socket path |
| AgentClient.socketPath(name) | string | Resolve the relay socket path without connecting |
| request(flags, body) | Promise<RawFrame> | Send one frame, await one response |
| stream(flags, body) | Promise<AgentStream> | Open a streaming session |
| send(id, flags, body) | Promise<void> | Send a follow-up frame on a correlation id |
| readyBytes() | Buffer | Cached core.ready handshake frame body |
| close() | Promise<void> | Close the connection (idempotent) |
AgentStream
Returned by stream()
An open raw agent stream. ImplementsAsyncIterableIterator<RawFrame>, so it can be driven with for await. The iterator ends after a frame carrying FLAG_TERMINAL or when the underlying stream is exhausted.
| Property / Method | Type | Description |
|---|---|---|
| id | number | Protocol correlation id; pass to send() for follow-up frames |
| next() | Promise<IteratorResult<RawFrame>> | Pull the next frame; done once terminal or exhausted |
| close() | Promise<void> | Release the stream handle early (idempotent) |
| return() | Promise<IteratorResult<RawFrame>> | Async-iterator early-exit hook; closes the stream |
| Symbol.asyncIterator | AgentStream | Returns itself so the stream is iterable |
RawFrame
Returned by request() · iterated from AgentStream
A raw protocol frame. Thebody is the CBOR-encoded Message body (v, t, p) as it appeared on the wire; decode it with a CBOR library such as cbor-x.
| Field | Type | Description |
|---|---|---|
| id | number | Correlation id from the frame header |
| flags | number | Frame flags (FLAG_TERMINAL, FLAG_SESSION_START, …) |
| body | Buffer | Raw CBOR-encoded body bytes |
AgentConnectOptions
Used by connectSandbox() · connect()
Options for connecting to an agent relay.| Field | Type | Description |
|---|---|---|
| timeoutMs | number | Handshake timeout in milliseconds. Defaults to 10_000. |