Skip to main content
The terminal guide shows how these pieces fit together. The browser entry points contain no server code and accept no API key.

Server

handleTerminalSession(cybr, deploymentId, options?)

Returns a Promise<Response>: the session as uncached JSON, or { message: <reason> } with a status the browser client understands. The guide lists the statuses. Pass a deploymentId only after your ownership check.

deployments.createTerminalSession(deploymentId, options?)

The lower-level call behind handleTerminalSession. Use it to build the response yourself.
It retries CONTAINER_STARTING until timeoutMs, which defaults to 30 seconds. The deadline throws timeout, and cancellation throws aborted. Other failures throw a CybrLabsError whose backendCode holds the reason.

supportsWebTerminal(lab)

Returns true for an AWS lab with webTerminal: true. Accepts a Lab or LabDetails.

Browser client

createTerminalClient(options)

startupBudgetMs defaults to 120000: how long to keep trying before the shell is first ready. maxAttempts defaults to 10: attempts after each drop. The count starts again once a connection stays up for a minute. TerminalState is idle, connecting, ready, reconnecting, closed, or disposed. Without autoReconnect, each connect() is one attempt. Within it, retryable refusals such as CONTAINER_STARTING are retried until connectionTimeoutMs. A dropped connection is not reconnected.

Client methods

TerminalCloseInfo

A plain shell exit, such as the learner typing exit, is retryable and not retried automatically. reconnect() opens a fresh shell.

TerminalReconnectInfo

fetchTerminalSession(url, init?)

POSTs to your session route without caching and resolves with the session. A non-2xx response throws TerminalRefusedError. Pass init for headers or a signal.

TerminalRefusedError

If you write your own getSession, throw a TerminalRefusedError so the client can tell a final refusal from one worth retrying.

terminalRefusalMessage(reason)

Returns learner-facing copy for a refusal reason. Unknown reasons get a generic message.

xterm.js adapter

The adapter does not depend on xterm.js. It works with any object of the same shape.

xtermCallbacks(term)

Returns { onOutput, onReset } to spread into createTerminalClient. Output goes to term.write, and each new connection calls term.reset().

attachXterm(term, client, options?)

Call after term.open(element). Returns a function that detaches everything; call it before disposing either side.

Other renderers

Without xterm.js, wire the callbacks yourself:
Output arrives as UTF-8 bytes. The WebSocket protocol documents the wire format for clients that do not use the SDK.