Skip to main content
Low-level raw CBOR transport for communicating with agentd through a sandbox relay.

Constants

FlagTerminal

Frame flag: this is the last message for the given correlation id. When a frame on an open stream carries this bit, no further frames will arrive for that id. Also available as FLAG_TERMINAL, the cross-SDK constant spelling.

FlagSessionStart

Frame flag: this is the first message of a new session. Set it on the opening frame of a request/response RPC or a streaming session. Also available as FLAG_SESSION_START.

FlagShutdown

Frame flag: this message requests sandbox shutdown. Also available as FLAG_SHUTDOWN.

Functions

m.ConnectAgentSandbox()

Connect to a running sandbox by name. Resolves the sandbox’s relay socket path and performs the core.ready handshake. Sandbox names are limited to 128 UTF-8 bytes. Use context.WithTimeout to override the default 10s handshake timeout.

Parameters

ctxcontext.Context
Bounds the handshake; defaults to a 10s timeout if none is set.
namestring
Sandbox name, up to 128 UTF-8 bytes.

Returns

Connected client.
error
Typed microsandbox error.

m.ConnectAgentPath()

Connect to an agentd relay socket by path. Use this when you already have the socket path, for example one returned by AgentSocketPath(). Use context.WithTimeout to override the default 10s handshake timeout.

Parameters

ctxcontext.Context
Bounds the handshake; defaults to a 10s timeout if none is set.
pathstring
Filesystem path of the relay socket.

Returns

Connected client.
error
Typed microsandbox error.

m.AgentSocketPath()

Resolve a sandbox’s agentd relay socket path without connecting. Returns the same path ConnectAgentSandbox() would dial internally (preferring the hashed path, falling back to the legacy name-derived path), so you can talk to agentd over a raw byte transport (for example a transparent relay that splices bytes between a WebSocket and the socket) instead of this frame client. The sandbox need not be running; the path is derived from the name and the configured home directory.

Parameters

namestring
Sandbox name, up to 128 UTF-8 bytes.

Returns

string
Relay socket path.
error
Typed microsandbox error.

AgentClient

Returned by ConnectAgentSandbox() · ConnectAgentPath()

Low-level client for raw agent frames.

c.Request()

Send one frame and await a single response frame. Use for request/response RPCs that produce exactly one terminal response (for example a core.fs.request to its core.fs.response).

Parameters

ctxcontext.Context
Cancels the request.
flagsuint8
Frame flag byte, e.g. FlagSessionStart.
body[]byte
CBOR-encoded protocol message body.

Returns

The single response frame.
error
Typed microsandbox error.

c.Stream()

Open a streaming session. The returned AgentStream carries the protocol correlation id (read it with ID() and pass it to Send() for follow-up frames), and yields frames one at a time via Next().

Parameters

ctxcontext.Context
Cancels opening the stream.
flagsuint8
Frame flag byte for the opening frame, e.g. FlagSessionStart.
body[]byte
CBOR-encoded protocol message body.

Returns

Open stream of raw frames.
error
Typed microsandbox error.

c.Send()

Send a follow-up frame on an existing correlation id (for example stdin, a signal, a resize, or data chunks on an open session). Use the id returned by AgentStream.ID().

Parameters

ctxcontext.Context
Cancels the send.
iduint32
Correlation id of an open session.
flagsuint8
Frame flag byte.
body[]byte
CBOR-encoded protocol message body.

Returns

error
Typed microsandbox error.

c.ReadyBytes()

Return the cached handshake core.ready frame body as CBOR bytes. Captured during connect, so this reads from the cached handshake rather than producing protocol traffic.

Returns

[]byte
CBOR-encoded core.ready frame body.
error
Typed microsandbox error.

c.Close()

Release the client handle. Idempotent: calling it more than once is safe.

Returns

error
Typed microsandbox error.

c.CloseCtx()

Release the client handle with a caller-controlled context. Like Close(), but lets you bound or cancel the teardown.

Parameters

ctxcontext.Context
Cancels the close.

Returns

error
Typed microsandbox error.

AgentStream

Returned by Stream()

An open raw agent streaming session. Drive it by calling Next() until it returns nil, which happens after a frame carrying FlagTerminal or when the underlying stream is exhausted.

s.Next()

Pull the next frame from the stream. Returns nil, nil at EOF, so loop until the frame is nil or carries FlagTerminal.

Parameters

ctxcontext.Context
Cancels waiting for the next frame.

Returns

Next frame, or nil at EOF.
error
Typed microsandbox error.

s.ID()

Return the protocol correlation id for this stream. Pass it to AgentClient.Send() for follow-up frames in the session.

Returns

uint32
Correlation id for this session.

s.Close()

Release the stream handle.

Parameters

ctxcontext.Context
Cancels the close.

Returns

error
Typed microsandbox error.

Types

RawFrame

Returned by Request() · yielded by Next()

A raw protocol frame. Body is the CBOR-encoded Message body (v, t, p) as it appeared on the wire; decode it with a CBOR library such as fxamacker/cbor.