WebSocket-based implementation of ContainerisedWorkspace that communicates with the workspace runner via WebSocket instead of HTTP.
This solves the threading issues of the HTTP version by:
- Using asynchronous WebSocket communication
- Implementing heartbeats over the same connection
- Supporting real-time streaming of command output
- Eliminating thread pool blocking during long commands
Commands run without a shell, and only programs on the runner's allowlist run (#1756): sandboxConfig, when given, chooses the list (and the paths, limits and network a command gets, design §4.39); otherwise the runner's WORKSPACE_SANDBOX_PROFILE (unset, permissive) does. extraAllowedCommands adds to either.
Only this client can drive the runner (#3046): the container's port is published on the host's loopback only (127.0.0.1:<hostPort>), and every WebSocket handshake carries a random token made for this container and passed to it in its environment, never on a command line. The runner refuses a handshake without it, and any browser's.
The runner never runs as root, and holds no capability (#3064): the container starts --cap-drop ALL with only what the image's entry point needs to set it up (see ContainerisedWorkspace.EntryPointCapabilities), and the entry point drops all of it as it switches to the workspace directory's owner (or ContainerOptions.runAsUser). The container's memory, pids and CPU limits are ContainerOptions'.
start says why a start failed (#3063), and refuses a runner that speaks another protocol version, an image older or newer than this client, naming both.
The container never outlives this client for long (#3053): it starts with --rm --init, a failed start removes whatever it left, stopContainer (or close) removes it even when docker stop fails, a JVM shutdown hook does the same when the JVM exits without calling either, and the runner exits by itself once no client has been connected for idleTimeout. A dropped connection (a long pause of this JVM, which the runner ends after 30 seconds without a message, or a runner that stops answering heartbeats) is reconnected with backoff; when that fails the container is removed and every later call throws a WorkspaceAgentException with code WORKSPACE_UNAVAILABLE. A command in flight when the connection dropped fails CONNECTION_CLOSED: the runner kills a closed connection's commands, and a file change's outcome is then unknown.
Value parameters
- commandCgroups
-
start the container so the runner can give each command a cgroup of its own and kill it whole, so a daemon a command starts (
setsid) cannot outlive it (design §4.39, #2008):--cgroupns=private --cap-add SYS_ADMIN --security-opt apparmor=unconfined. The image's entry point usesSYS_ADMINonly to make the container's cgroup writable, and drops it before the runner starts. Off by default: commands' daemons can then outlive them, as the runner logs at startup - extraAllowedCommands
-
programs the runner may run besides its profile's allowlist (for example
sbt), passed to the container asWORKSPACE_EXTRA_COMMANDS; each is a bare program name, never a shell or a launcher (see WorkspaceSandboxConfig.withExtraCommands), and a container is not started with a name the runner would refuse - hostPort
-
the host port the container's 8080 is published on, on
127.0.0.1only (or ContainerOptions.publishAddress);0lets Docker choose a free one, read back once started (port), so two workspaces never contend for one (#3063) - idleTimeout
-
how long the runner waits with no client connected before it exits, and its container is removed (#3053); rounded up to whole seconds. Longer than this client's reconnection (about 20 seconds), so a reconnecting client finds the runner still there
- imageName
-
the workspace-runner image
- options
-
how the container is started beyond the sandbox: the startup wait, memory, pids and CPU limits, the user the runner runs as, and where its port is published (#3063, #3064)
- sandboxConfig
-
the runner's whole sandbox config, passed as
WORKSPACE_SANDBOX_CONFIG;Noneleaves the runner on its profile. WithnetworkAllowed = false(the default, and the permissive profile's) the container itself has no egress (#870): it starts with--cap-add NET_ADMIN -e LLM4S_NO_EGRESS=1, and the image's entry point lets it answer the published port but open no connection out, then dropsNET_ADMINbefore the runner starts. A Docker host where the entry point cannot set that up does not start the container - workspaceDir
-
the host directory mounted as the container's
/workspace
Attributes
- Companion
- object
- Source
- ContainerisedWorkspace.scala
- Graph
-
- Supertypes
