Runner service
The runner service is a standalone HTTP service that gives the platform a controlled way to run workflow tools in isolated containers. It accepts execution requests, starts the selected tool image, relays tool output, reports the run result, and manages cleanup. Its separate deployment boundary lets the platform scale or secure container execution without coupling it to the main platform service. See Platform support services for its place in the service group and Platform service for the related platform-facing service.
Service role
The runner service is the execution support layer between a caller that manages a workflow and the container runtime that runs a tool. It does not define the workflow itself. Instead, it turns the caller’s execution data into a tool-container run and returns a stable result that the caller can use to advance the workflow.
The service also keeps execution concerns in one boundary. Image access, container naming, environment transfer, log handling, status lookup, and cleanup stay behind the runner API. This allows the caller to request tool work without owning the container runtime directly.
HTTP interface
The HTTP interface exposes health, execution, status, cleanup, and tool metadata operations below /v1/api. A caller uses the run operation for a workflow execution and can use the other operations to monitor or recover a container when needed.
flowchart LR
Caller[Workflow caller] --> API[Runner HTTP API]
API --> Run[Run tool container]
API --> Status[Read container status]
API --> Remove[Remove container]
API --> Metadata[Read tool metadata]
Run --> Runtime[Container runtime]
Status --> Runtime
Remove --> Runtime
Metadata --> Runtime
Run --> Events[Execution logs and result]
Endpoint responsibilities
The run endpoint receives the tool image and execution context. It returns a result record that indicates whether the tool run succeeded or failed. Status and removal endpoints provide separate control for a named container. The metadata endpoint runs a limited set of read commands against a tool image so callers can discover tool properties, specification, variables, or icon data.
The health endpoint returns a simple success response for service checks. All routes are registered under the versioned API blueprint, which gives callers one stable service prefix.
References: runner/…/run.py• L8-78 runner/…/health.py• L7-14 runner/…/__init__.py• L6-9
Application entrypoint
The application entrypoint is the Flask object exported as unstract.runner:app. The service assembles this object by loading logging, error handling, request ID support, and the versioned route group before the web server accepts requests.
The process entrypoint is runner/entrypoint.sh. It starts Gunicorn on port 5002 with a threaded worker setup and a long request timeout suited to tool runs. A development flag enables reload behavior; production mode uses the same application without reload.
Startup responsibilities
Startup establishes the service boundary rather than performing tool work. It applies environment-based logging, installs shared error and request middleware, and registers the health and container routes. Each request then creates the runner coordination object for the image and tag involved in that operation.
References: runner/…/__init__.py• L4-27 runner/entrypoint.sh• L1-42 runner/pyproject.toml• L39-56
Source modules
The source is grouped by service concern. The groups form a short path from HTTP request to container action and keep the runtime-specific part replaceable.
Application assembly
The package initializer creates the Flask application and connects shared service behavior to the route tree. It is the main place to understand how the independently deployable process becomes a web service.
References: runner/…/__init__.py• L1-29 runner/…/__init__.py• L1-9
Request controllers
The controller modules translate HTTP requests into runner operations. The health controller serves service checks. The run controller handles tool execution and the supporting status, removal, and metadata actions.
References: runner/…/health.py• L1-14 runner/…/run.py• L1-78
Execution coordinator
UnstractRunner coordinates one tool operation from setup through result. It prepares the execution environment, starts the requested container, consumes its output, publishes accepted messages when a channel is present, checks shared execution status, and performs final cleanup. It also converts image and tool failures into result records that callers can handle.
References: runner/…/runner.py• L38-47 runner/…/runner.py• L408-577
Container client boundary
The client interface defines the container operations needed by the coordinator. The default client uses Docker, but the boundary permits another container runtime or test client without changing the HTTP controllers or the execution flow.
References: runner/…/interface.py• L9-145 runner/…/helper.py• L10-17
Runtime support
The Docker client maps runner actions to the host Docker daemon. It finds or pulls images, builds run settings, starts containers, exposes status, and removes containers and shared log volumes. Utility and exception modules provide the small set of policy checks and named errors used across this path.
References: runner/…/docker_client.py• L63-83 runner/…/docker_client.py• L159-275 runner/…/utils.py• L15-117 runner/…/exception.py• L1-20
Tool execution lifecycle
The runner turns one request into an isolated tool run. The execution context identifies the organization, workflow, execution, and file execution so the tool receives the correct data location and the caller can match logs and results to the right work.
When a caller submits a run, the service follows this sequence:
- It builds the tool command and execution environment.
- It marks the file execution as being in the tool-execution stage.
- It resolves the tool image and creates the container settings.
- It starts the container and consumes its output.
- It maps tool messages to logs, UI updates, or a final result.
- It reports success or a named failure and removes runtime resources when configured to do so.
This diagram shows the main path and the point at which execution data and live messages leave the runner.
sequenceDiagram
participant Caller
participant Runner
participant Docker
participant Tool
participant Tracker as Execution tracker
participant Bus as Message channel
Caller->>Runner: Submit tool image and execution context
Runner->>Tracker: Mark tool stage in progress
Runner->>Docker: Resolve image and start container
Docker->>Tool: Run tool command
Tool-->>Runner: Logs, updates, and result messages
Runner-->>Bus: Publish enriched messages when requested
Runner->>Tracker: Read final tool status
Runner-->>Caller: Success or error result
Runner->>Docker: Clean up container and shared resources
Execution context
The service adds a file-specific execution directory to the tool environment. It also passes storage credentials and any permitted extra environment values. This gives the tool access to the data for one file execution without making the caller manage container mount details.
References: runner/…/runner.py• L431-467 runner/…/docker_client.py• L218-275
Tool messages
The runner accepts structured tool messages with a known type. Normal logs stay in service logs. Result messages end the normal stream path. Update messages receive the tool instance as their component identity. When a messaging channel is supplied, the runner adds execution identity and time data before publishing the message.
Malformed or unknown messages do not become execution results. A tool error message raises a tool-run failure, which the service returns as an error result to the caller.
References: runner/…/runner.py• L49-129 runner/…/constants.py• L1-18
Resource cleanup
The runner can remove a tool container after the run. A named removal operation supports recovery when a caller needs to clean up outside the normal request path. The cleanup policy applies to the main container and, when enabled, its sidecar and shared log volume.
References: runner/…/runner.py• L390-406 runner/…/runner.py• L573-577 runner/…/docker_client.py• L52-60 runner/…/docker_client.py• L150-157
Isolated execution support
The runner keeps tool processes outside the web process by placing each run in a container. The container uses the configured tool image and network. The runner can pull an image when it is not available locally and can log in to a private registry when the deployment provides registry credentials.
Sidecar logging
An optional sidecar mode separates tool execution from log handling. The main tool and sidecar share a log volume. The sidecar receives the execution identity and messaging settings so it can support log delivery while the tool runs. Sidecar mode is active only when its enable flag and image settings are complete.
The sidecar also receives the selected log transport and stream queue name. These values keep its log publisher on the same path as the rest of the deployment. The default transport remains Celery, while a Redis transport can use the configured Redis access and queue name.
The sidecar also receives configured Redis connection settings such as TLS and database selection. These settings keep its own log publisher and status client on the same Redis endpoint as the rest of the deployment. Unset settings remain absent so deployments that use the default Redis connection keep their existing behavior.
This mode changes how output is collected and how the two containers are stopped. It does not change the caller’s run endpoint or the result contract.
References: runner/…/runner.py• L217-289 runner/…/runner.py• L489-532 runner/…/constants.py• L47-53 runner/…/test_sidecar_log_transport.py• L1-175 runner/…/utils.py• L76-105 runner/…/docker_client.py• L232-250
Deployment boundary
The runner is packaged as its own Python application and container image. The image includes the Docker command-line client and runs the service on port 5002. At runtime, the service must be able to reach the host Docker endpoint and the message or broker services required by the selected execution mode.
The deployment supplies the tool network, image settings, cleanup policy, execution-data settings, broker access, and optional registry or sidecar settings. These values are part of the contract between the runner deployment and the caller that creates tool runs.
Operational dependencies
The most important external dependencies are:
- A Docker daemon that can create and inspect tool containers.
- A tool image registry when the selected image is not local.
- The configured tool-container network.
- Broker and Redis access when the execution path or sidecar uses message delivery.
- Shared execution storage settings so the tool can read and write its file data.
References: docker/…/runner.Dockerfile• L1-18 docker/…/runner.Dockerfile• L20-34 docker/…/runner.Dockerfile• L63-87 runner/README.md• L18-49 runner/…/constants.py• L20-53
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the public route prefix and result shape aligned with the service that submits and tracks tool executions.
- Keep tool message types and the execution identity fields aligned with the shared logging and update consumers.
- Keep container naming rules aligned across run, status, removal, sidecar, and cleanup paths.
- Keep image and sidecar settings aligned with the container image, registry access, and deployment network.
- Keep execution-directory and storage-credential handling aligned with the tool contract and workflow execution service.
- Keep the log transport and stream queue settings aligned between the runner, the sidecar environment, and the active log consumer. A missing value can silently select a different transport.
- Keep Redis connection settings aligned between the runner and sidecar. Missing TLS, database, or URL settings can send sidecar logs to a different Redis endpoint or database without a clear startup error.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The requested tool image cannot be found or pulled | The run returns an error with the stable TOOL_IMAGE_NOT_FOUND code | Publish the tool image with the requested name and tag, and provide registry access when needed |
| The runner cannot reach the Docker daemon | Container start, status, and cleanup operations fail | Expose a working Docker endpoint to the service container or host process |
| Sidecar mode is enabled without a sidecar image name and tag | The runner falls back to normal single-container execution | Set both sidecar image values before enabling the mode |
| The sidecar does not receive the selected log transport or queue name | Tool logs can use a different path from other publishers or reach a queue that no consumer drains | Forward the transport and queue settings to the sidecar and keep them aligned with the log consumer |
| The sidecar does not receive the deployment’s Redis connection settings | The sidecar can use plaintext Redis or a different database and its logs or status data can disappear without a clear service failure | Forward configured TLS, database, URL, and health-check settings while omitting values that are not configured |
| A tool emits an error log message or the shared tracker reports failure | The run returns a tool execution error instead of success | Inspect the tool log and execution status for the source failure |
| Container removal is disabled or cleanup cannot reach Docker | Containers or log volumes can remain after execution | Set the cleanup policy for the deployment and monitor runtime resources |
Key files
| File | Why to read it |
|---|---|
| runner/entrypoint.sh | Shows how the deployable web process starts and which port it serves. |
| runner/…/__init__.py | Shows application assembly and the exported app entrypoint. |
| runner/…/run.py | Defines the public container execution and control operations. |
| runner/…/runner.py | Explains the end-to-end coordination of tool execution, messages, status, sidecar transport, Redis settings, and cleanup. |
| runner/…/constants.py | Defines the message types and deployment settings that form part of the runner-to-sidecar contract. |
| runner/…/interface.py | Defines the runtime boundary that keeps container concerns replaceable. |
| runner/…/docker_client.py | Shows the default Docker-backed execution behavior. |
| runner/…/utils.py | Defines cleanup, sidecar, and basic runtime policy checks. |
| runner/…/test_sidecar_log_transport.py | Captures the sidecar log transport, Redis connection, and safe-default contracts. |
docker/dockerfiles/runner.Dockerfile | Shows the independently deployable runner image and its runtime needs. |