The executor client is the hand end: it fetches a short-lived executor token, connects out to BMA (or a local harness), registers with its capabilities, heartbeats, reconnects with resume, and serves the session and tool requests sent to it. Register tool handlers and protocol handlers before start.
Generated from bma-executor-sdk 1.3.0 and its contract (contracts/bma/executor, protocol bma.executor.v1.1). Install, credentials and quick starts are on the bma-executor-sdk overview; the protocol itself is described in Executor Protocol.

Create a client

Validates the options and returns a disconnected client; the long-lived credential (environment key or machine token) is only sent to the token endpoint.

Client options

Base URL, credential, executor identity, capabilities, reconnect and tool-result retry budgets, and the hook that receives a tool result every retry failed to deliver.

start

Fetches an executor token, connects, sends executor.register and starts heartbeats. After a failed start the client may be started again.

stop

Sends executor.close, closes the connection and fails pending calls.

Done / Err / waitClosed

Report when the client stops for good (stop, executor.close, a terminal close code such as 4004 replaced, a rejected credential, or exhausted reconnects). In Go, Done closes and Err explains why; in Python and TypeScript, wait_closed() / waitClosed() return after a stop and raise on any other end, so the process can exit and a supervisor restart it.

WaitReady / waitReady / wait_ready

Wait until the executor is registered and the registration stayed open for one heartbeat interval. The state turns ready as soon as executor.register returns, which a refused registration also does (a machine-scoped executor that declares neither the process nor the agent capability is closed with 4002 right after), so only this wait separates a usable executor from one about to be refused. It returns the error of a client that ended, and fails on timeout.

state

The current connection state.

executorId / connectionId / protocol

The executor id assigned by executor.register, the current connection id and the negotiated subprotocol.

activeSessions

The sessions currently assigned to this executor.

sessionContext / sessionContextById

Read the session a process or session id belongs to, with its metadata, over the machine token of a machine-scoped executor (no environment id). Answers are cached per session; a missing session and a client that is not machine-scoped are distinct errors.

RefreshModelToken

Asks the platform for a fresh model credential for a running turn (model_token.refresh): call it before the turn.start model_token expires. One attempt, the caller owns retry and backoff; an ended turn answers turn_inactive, a platform that issues this machine no model token answers forbidden or model_token_unavailable.

onSessionAssign

Registers the session.assign handler, which prepares the workspace and MCP servers of a new session.

onSessionStop

Registers the session.stop handler; stop the session’s processes and MCP servers before answering.

onDrain

Registers the executor.drain handler; a draining executor accepts no new sessions.

OnToolCallAccept

Go only: a check run before a tool.call is acknowledged; an error answers the request (an *RPCError keeps its code) and the tool does not run.

sessionReady

Reports session.ready after workspace and MCP setup complete; only your code knows when that is.

sessionEnded

Reports session.ended once every process and MCP server of the session has stopped; the session then leaves the active sessions.

reportToolResult

Sends tool.result once per tool_call_id, retrying executor_busy, timeout and disconnects with backoff across reconnects. Tool handlers call it for you; use it for results you produce yourself.

UploadArtifact

Go only: uploads an artifact with the current executor token (POST /v1/executors/artifacts, idempotent by session and digest); finish it before a tool.result references the artifact.

openMcpChannel

Opens the MCP channel of one environment-owned MCP server from session.assign.mcp_servers; frames are raw MCP JSON-RPC.

updateCapabilities

TypeScript: publishes changed capabilities with executor.capabilities.update. Registering a tool handler after start does this in every language.

onRequest

Serves one harness-to-executor capability request (process.*, terminal.*, skill.install, workspace.backup); see Process, terminal & machine.

call / notify

Sends a typed executor-to-harness request or notification (for example session.event, tool.progress); see Protocol methods.

sessionEvent / sessionStatus / toolProgress

TypeScript shortcuts for session.event, session.status and tool.progress; the other languages use call / notify with the method.

serveAgent

Advertises the agent capability and routes the agent methods to your handler; call it before start. See Agent.

staticToken

A token source for a harness reached directly, typically a local harness; the token may be empty when the harness has no authenticate hook.

MCP channel

The executor end of an MCP channel; read and write one raw MCP JSON-RPC frame at a time.

Local transports

Listen as the executor on a local Unix socket or Windows named pipe, so the next local harness (brain) that dials it drives this hand; the roles stay the same: the executor still registers.