# Get the Runtime Adapters

These instructions apply to the current Admin Console.

{% hint style="info" %}
Contextual Workers are in early access and may not be available in your account. [Contact Contextual support](mailto:help@contextual.io) to request that Workers be enabled for your tenant.
{% endhint %}

The runtime adapters are not published to npm, crates.io, a Go proxy, or PyPI. Each adapter is a base image on the platform's image host. The Rust, Go, and Python images also contain their language's library. You get both by pulling the image with your Contextual CLI login. You do not need access to the platform source repository.

## Before You Start

You need Docker and the Contextual CLI with a signed-in configuration. Follow step 1 of [Deploy Your First Worker](https://docs.contextual.io/build/contextual-workers/quickstart.md#1-check-the-cli-and-connect-to-your-tenant) if you have not set them up.

Configure Docker to use your CLI login for the image hosts:

```sh
ctxl workers configure-docker --pretty
```

## The Adapter Images

| Language | Image | Library in the Image |
| --- | --- | --- |
| TypeScript or JavaScript (Node 24) | `images.contextual.io/worker/base/worker-adapter-node:0.10.0` | None in 0.10.0. The adapter supplies the handler's context at run time. See the TypeScript tab below. |
| Rust (1.88 or later) | `images.contextual.io/worker/base/worker-adapter-rust:0.7.0` | `/opt/contextual/worker-adapter-rust/contextual-worker`, the `contextual-worker` crate |
| Go (1.26 or later) | `images.contextual.io/worker/base/worker-adapter-go:0.4.0` | `/opt/contextual/worker-adapter-go`, the `contextual.io/worker` module |
| Python (3.14) | `images.contextual.io/worker/base/worker-adapter-python:0.4.0` | `/opt/contextual/worker-adapter-python/contextual_worker`, the `contextual_worker` package |

Check that you can pull your language's image:

```sh
docker pull --platform linux/amd64 images.contextual.io/worker/base/worker-adapter-node:0.10.0
```

If Docker reports `unauthorized` or `denied`, see [Troubleshooting](https://docs.contextual.io/build/contextual-workers/managed-workers/troubleshooting.md#the-adapter-image-cannot-be-pulled).

## How the Adapter Gets into Your Image

You never install an adapter from a package registry, and you never write the Dockerfile for the image that runs. The adapter image does three jobs:

* **Library.** In Rust, Go, and Python, it contains the library your code imports. Copy it into your project for your editor, tests, and coding agent. Its types and doc comments are the most exact API reference for that version.
* **Build input.** In Rust and Go, your `Dockerfile.build` copies the library from the adapter image again and compiles your binary against it.
* **Base image.** Its `package` command writes the Docker build directory for your app image, `FROM` the same adapter image. The CLI builds and pushes that image when you create or update the Worker.

The whole path, for every language:

1. **Pull and copy.** Configure Docker as above, pull your language's adapter image, and copy the library into your project. See [Copy the Library into Your Project](#copy-the-library-into-your-project).
2. **Write the handler** against the copied library: a `path` dependency in Rust, a `replace` directive in Go, `PYTHONPATH` in Python. See [Write the Handler and Manifest](https://docs.contextual.io/build/contextual-workers/managed-workers/get-started.md#1-write-the-handler-and-manifest).
3. **Build.** Rust and Go compile a `linux/amd64` binary with a `Dockerfile.build` that starts `FROM` the adapter image. TypeScript bundles the module into one file. Python has nothing to compile. See [Build](https://docs.contextual.io/build/contextual-workers/managed-workers/get-started.md#2-build).
4. **Package.** Run the adapter image's `package` command. It checks `worker.json`, hashes the release, and writes `.worker-image`, whose Dockerfile is `FROM` the adapter image. See [Package the Release](https://docs.contextual.io/build/contextual-workers/managed-workers/get-started.md#3-package-the-release).
5. **Deploy.** `ctxl workers create --managed <template>:<version> --build .worker-image` builds the app image, pushes it to your organization's image host, and deploys it. See [Create the Worker](https://docs.contextual.io/build/contextual-workers/managed-workers/get-started.md#4-create-the-worker).

Use one adapter version for all of it: the library you copy, the `Dockerfile.build` stage, and the `package` command. Your local copy and the build stage are two copies of the same library, so a version mismatch builds against one API and runs on another. Deploy it on the template version released with that adapter. See [Release Versions](https://docs.contextual.io/build/contextual-workers/managed-workers.md#release-versions).

When you upgrade, change the version in all three places, delete the old copy, and copy the library again. Copying into an existing directory can nest the new copy inside the old one, and it keeps the old files.

## Copy the Library into Your Project

Run these commands from your project directory. They copy the library into `.contextual/` or the path shown, replacing an earlier copy. Add the copied directory to `.gitignore`. Each command runs `cp` inside the image as your own user, so the copied files belong to you.

{% tabs %}
{% tab title="TypeScript" %}
The 0.10.0 TypeScript image contains no library to copy. Its runner loads your bundled module and supplies the handler's `context` at run time, so your code imports nothing from the adapter. Install only the build tools:

```sh
npm install --save-dev esbuild typescript @types/node
```

Your module default-exports the Worker: an object with `apiVersion: "1"`, `name`, `version`, `parseConfig`, and `run`, and optionally `start` and `stop`. Another handler is a named export function. Until an adapter release publishes the context's types, describe them yourself. Save this as `src/worker-types.ts` and extend it with the methods you use, from [Platform Capabilities](https://docs.contextual.io/build/contextual-workers/managed-workers/capabilities.md):

```ts
// The parts of the managed Worker context this app uses. Adapter 0.10.0 publishes no types.
export type Fields = Record<string, unknown>
export type Logger = Record<"debug" | "info" | "warn" | "error", (message: string, fields?: Fields) => Promise<void>>
export type Invocation = { id: string, payload: unknown, trigger: { type: "topic" | "http" | "cron", [field: string]: unknown } }
export type Context<Config> = {
  config: Config
  logger: Logger
  signal: AbortSignal
  invocationId: string
  correlationId: string
  // The capability namespaces (records, attachments, ai, and the rest), typed loosely.
  [namespace: string]: any
}

/** A failed capability call: an Error named PlatformError, with the fields on the Platform Capabilities page. */
export type PlatformFailure = Error & { code: string, reason?: string, retryable: boolean, effectMayHaveOccurred: boolean, responseStatus?: number }
export const isPlatformError = (error: unknown): error is PlatformFailure => error instanceof Error && error.name === "PlatformError"
```

Bundle your Worker into one CommonJS file with esbuild or another bundler. See [Build Your First Managed Worker](https://docs.contextual.io/build/contextual-workers/managed-workers/get-started.md).
{% endtab %}

{% tab title="Rust" %}
```sh
rm -rf contextual-worker
docker run --rm --platform linux/amd64 -u "$(id -u):$(id -g)" --entrypoint cp \
  -v "$PWD:/out" \
  images.contextual.io/worker/base/worker-adapter-rust:0.7.0 \
  -r /opt/contextual/worker-adapter-rust/contextual-worker /out/contextual-worker
```

Use it as a path dependency in `Cargo.toml`:

```toml
[dependencies]
contextual-worker = { path = "contextual-worker" }
# For attachment uploads and downloads, turn on the transfers feature instead:
# contextual-worker = { path = "contextual-worker", features = ["transfers"] }
```

The crate's `src/lib.rs` lists everything it exports. Its `examples/` directory has complete Workers.
{% endtab %}

{% tab title="Go" %}
```sh
rm -rf contextual-worker
docker run --rm --platform linux/amd64 -u "$(id -u):$(id -g)" --entrypoint cp \
  -v "$PWD:/out" \
  images.contextual.io/worker/base/worker-adapter-go:0.4.0 \
  -r /opt/contextual/worker-adapter-go /out/contextual-worker
```

Point the module at the copy in `go.mod`:

```
require contextual.io/worker v0.0.0

replace contextual.io/worker => ./contextual-worker
```

The module has no dependencies. Its `README.md` and `examples/` directory are in the copy.
{% endtab %}

{% tab title="Python" %}
```sh
rm -rf .contextual && mkdir -p .contextual
docker run --rm --platform linux/amd64 -u "$(id -u):$(id -g)" --entrypoint cp \
  -v "$PWD/.contextual:/out" \
  images.contextual.io/worker/base/worker-adapter-python:0.4.0 \
  -r /opt/contextual/worker-adapter-python/. /out
```

Put the copy on `PYTHONPATH` for your editor and tests:

```sh
export PYTHONPATH="$PWD/.contextual"
```

Import the package as `contextual_worker`. The image already contains the package at run time, so do not list it in `requirements.txt`. The copy includes the package `README.md` and `examples/`.
{% endtab %}
{% endtabs %}

For Rust and Go, your build also copies the library from the adapter image, in a `Dockerfile.build` stage. The local copy is for your editor and tests. See [Build Your First Managed Worker](https://docs.contextual.io/build/contextual-workers/managed-workers/get-started.md).

## Give the Library to a Coding Agent

A coding agent writes better Worker code when it reads the library source than when it guesses from memory. After you copy the library, point the agent at it:

| Language | What to Point the Agent At |
| --- | --- |
| TypeScript | `src/worker-types.ts` and [Platform Capabilities](https://docs.contextual.io/build/contextual-workers/managed-workers/capabilities.md). The 0.10.0 image has no library source, so the capabilities page is the API reference. |
| Rust | `contextual-worker/src/lib.rs`, `capabilities.rs`, `helpers.rs`, `context.rs`, and `examples/` |
| Go | `contextual-worker/README.md`, `capabilities.go`, `helpers.go`, `context.go`, and `examples/` |
| Python | `.contextual/README.md`, `contextual_worker/capabilities.py`, `helpers.py`, `context.py`, and `examples/` |

See [Build with a Coding Agent](https://docs.contextual.io/build/contextual-workers/managed-workers/coding-agents.md) for a complete brief.
