Turn it on
Turn the terminal on for any of your own labs. It applies right away, without a Cybr review. Currently, only AWS labs are supported.- Dashboard: check Enable web terminal in the lab editor and save.
- Cybr Labs MCP: call
update_labwithwebTerminal: true.
Check availability
AWS labs with the web terminal turned on come with one. Check before you show it:Add the session route
Add a POST route that checks ownership and then callshandleTerminalSession:
handleTerminalSession returns a ready, uncached Response:
It waits up to 10 seconds for a starting terminal before it answers
CONTAINER_STARTING. The browser client retries that answer on its own. Use onError to log the original error.
A session is valid for at most 15 minutes and opens one connection. Do not log or store it.
Connect from the browser
Install xterm.js and its fit addon, then connect with the terminal client and the xterm adapter:container, showState, showReconnecting, showMessage, showLabEnded, and offerReconnect are your UI code.
xtermCallbacks(term)writes output to the terminal. It also clears the terminal before each connection, because the server replays recent output on every connection.attachXterm(term, client, { fit })sends typing and size changes to the shell. It refits when the element resizes or the page becomes visible, sends the shell a new size once it stops changing, and copies a selection on Ctrl+C or Cmd+C. With nothing selected, Ctrl+C still interrupts the shell.connect()rejects when the terminal cannot open. The callbacks already report that, so thecatchonly prevents an unhandled rejection.
Reconnect automatically
WithautoReconnect: true, the client fetches a new session and tries again after a dropped connection and while the terminal starts. It keeps trying for up to 2 minutes before the shell is first ready, then up to 10 attempts after each drop. The state is reconnecting while it retries.
onReconnect fires before each retry. Use cause to pick the status text:
The info also includes
attempt, maxAttempts, delayMs, and the close code when a connection closed.
When the terminal closes
WithautoReconnect, onClose fires once, when the client stops trying:
labEnded: truemeans the lab ended. Tell the learner to launch the lab again for a new terminal.retryable: truemeansclient.reconnect()may work. This includes a learner typingexit: reconnecting opens a fresh shell.retryable: falsemeans a new connection cannot help.
onError only. If your route refused the session, the error is a TerminalRefusedError.
Refusals
fetchTerminalSession throws TerminalRefusedError for a non-2xx response. Its reason is the message from your route, and its message is copy you can show the learner:
Other 429 and 5xx responses are also retried.
terminalRefusalMessage(reason) returns the learner copy for any reason, including your own.
Connection limits
Each lab allows up to 4 terminal connections at once, so a learner can open the terminal in at most 4 tabs. A fifth connection fails.Content Security Policy
The browser connects straight to the terminal host. If your site sets a Content Security Policy, allow the terminal host inconnect-src. Today that is wss://*.on.aws; we’ll announce any change.
