Skip to main content
The web terminal has two parts. Your server creates a short-lived terminal session for the learner’s own deployment. The browser uses that session to open a WebSocket straight to the lab’s terminal. The API key never reaches the browser.

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_lab with webTerminal: true.
Turn it off the same way. New terminal sessions for that lab are then refused.

Check availability

AWS labs with the web terminal turned on come with one. Check before you show it:
Show the terminal once the deployment is ready. Other labs refuse terminal sessions.

Add the session route

Add a POST route that checks ownership and then calls handleTerminalSession:
Take the deployment ID only from your own records, never from the request. The API issues a session for any deployment in your organization. See tracking deployments. 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:
When the view closes, release everything:
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 the catch only prevents an unhandled rejection.
Install the npm package and bundle it whenever your site has a build step. If it has none, the browser entries also load straight from a CDN, with no bundler:
The terminal reference lists every option, including how to use a renderer other than xterm.js.

Reconnect automatically

With autoReconnect: 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

With autoReconnect, onClose fires once, when the client stops trying:
  • labEnded: true means the lab ended. Tell the learner to launch the lab again for a new terminal.
  • retryable: true means client.reconnect() may work. This includes a learner typing exit: reconnecting opens a fresh shell.
  • retryable: false means a new connection cannot help.
A failure before any connection opened reaches 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 in connect-src. Today that is wss://*.on.aws; we’ll announce any change.