org.llm4s.workspace

Members list

Type members

Classlikes

final case class ContainerOptions

How ContainerisedWorkspace starts its container, beyond the sandbox: how long it waits for the runner, the container's resource limits, the user its runner runs as, and where its port is published (#3063, #3064).

How ContainerisedWorkspace starts its container, beyond the sandbox: how long it waits for the runner, the container's resource limits, the user its runner runs as, and where its port is published (#3063, #3064).

Built with ContainerOptions() and its with* setters; new options are added with defaults.

Value parameters

connectHost

the host this client connects to; None is publishAddress, or 127.0.0.1 when that is a wildcard (0.0.0.0, ::). A remote DOCKER_HOST's own name, or host.docker.internal

cpus

the CPUs the container may use (--cpus, fractional). None is no limit

memoryBytes

the container's memory limit (docker run --memory, with --memory-swap the same, so it has no swap beyond it): the runner and every command together. At least 6 MiB, Docker's least. None, the default, is Docker's: no limit

pidsLimit

the most processes and threads the container holds at once (--pids-limit), the runner's JVM threads among them, so allow it a few hundred. None is no limit

publishAddress

the Docker host's address the runner's port is published on: 127.0.0.1, the default, so nothing beyond the Docker host can reach it (#3046). A remote DOCKER_HOST needs an address this client can reach; the token still guards every handshake, but the connection is plain ws://, so use a network you trust

runAsGroup

the gid the runner runs as; None is the workspace directory's group, or the uid's own

runAsUser

the uid the runner, and so every command, runs as. None, the default: the owner of the mounted workspace directory, so on a Linux host the files a command makes are the host user's; or, when that is root (a Docker Desktop mount, a root-owned directory), uid 1001. The runner never runs as root unless this says 0, which only rootless Docker needs (its container root is the host user). The image's entry point starts as root with only the capabilities it needs to set the container up, and drops them all before the runner starts

startupTimeout

how long ContainerisedWorkspace.start waits for the runner to accept a connection once docker run has returned, before it gives up, removes the container and reports why, with the container's logs. A first run of an image whose JVM is slow to start may need more

Attributes

Companion
object
Source
ContainerOptions.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
ContainerOptions.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
class ContainerisedWorkspace(val workspaceDir: String, val imageName: String, val hostPort: Int, val extraAllowedCommands: Set[String], val sandboxConfig: Option[WorkspaceSandboxConfig], val commandCgroups: Boolean, val idleTimeout: FiniteDuration, val options: ContainerOptions) extends WorkspaceAgentInterface, AutoCloseable

WebSocket-based implementation of ContainerisedWorkspace that communicates with the workspace runner via WebSocket instead of HTTP.

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 uses SYS_ADMIN only 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 as WORKSPACE_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.1 only (or ContainerOptions.publishAddress); 0 lets 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; None leaves the runner on its profile. With networkAllowed = 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 drops NET_ADMIN before 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
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
class
Source
ContainerisedWorkspace.scala
Supertypes
class Object
trait Matchable
class Any
Self type