Code packages
A code package is your own code, in any language, packaged as a container image. A workspace admin registers it once. After that, anyone building workflows can add a Code package step that runs it, with a form for its inputs.
Code packages run only on your own self-hosted workers, never on Blokkio's hosted workers. Third-party code (npm or NuGet packages, compiled tools, ML models) can't run safely on shared machines, but it can run on yours.
Blokkio cloud your machine
┌──────────────────────────┐ job + package ┌─────────────────────────────────────────┐
│ "Code package" step │ ───────────────▶ │ blokkio worker │
│ package: image@digest, │ │ checks: enabled? registry allowed? │
│ allowed pools, limits │ ◀── output JSON ─│ docker run ─▶ your container (once) │
└──────────────────────────┘ └─────────────────────────────────────────┘
How a package runs
For each step run, the worker starts a new container from the package image and removes it when it finishes.
| What | How |
|---|---|
| Input | The step's inputs as one JSON object on stdin, e.g. {"pages": 3, "mode": "fast"}. |
| Output | One JSON value on stdout. An object becomes the step's output; anything else becomes {"result": …}. |
| Success / failure | Exit code 0 means success. Any other exit code fails the step. |
| Error message | On failure, print {"error": "what went wrong"} on stdout. Otherwise the step shows the exit code and the end of stderr. |
| Files in | Files passed in the step's Files field are in /work/in/. |
| Files out | Files the package writes to /work/out/ come back as the step's files list (one file reference each). |
| Logs | Write anything that isn't the result to stderr, never stdout. |
| Time limit | Stopped when the time limit runs out (the step fails with "was stopped after N seconds"). |
| Memory limit | Stopped when it uses more memory than its limit ("ran out of memory"). |
| Network | None, unless the admin allowed network for the package. |
The BLOKKIO_WORK_DIR environment variable is set to /work.
A minimal package
#!/bin/sh
input=$(cat) # {"name": "Ada"}
name=$(echo "$input" | sed -n 's/.*"name": *"\([^"]*\)".*/\1/p')
if [ -z "$name" ]; then
echo '{"error": "name is required"}'
exit 1
fi
mkdir -p /work/out
echo "Hello, $name" > /work/out/greeting.txt
printf '{"greeting": "Hello, %s"}' "$name"
FROM alpine:3.20
COPY run.sh /run.sh
ENTRYPOINT ["/bin/sh", "/run.sh"]
Build and push it, then copy the digest that the push prints:
docker build -t ghcr.io/acme/greeter:1.0 .
docker push ghcr.io/acme/greeter:1.0
# 1.0: digest: sha256:4f6e… ← you need this
In Python or Node the idea is the same: read all of stdin, parse JSON, print one JSON value.
Register a package (admins)
Settings → Code packages → Add package. Only workspace admins can add, change or remove packages. Every change is recorded in the audit log.
| Field | What to enter |
|---|---|
| Name | What people pick on the step, e.g. PDF to text. |
| Image | The image pinned by digest: ghcr.io/acme/greeter@sha256:4f6e…. Tags such as :latest are refused, because a tag can later point to different code than the code you approved. |
| Inputs | The fields the step's form shows (name, type, required, allowed values). |
| Outputs | The fields the package returns. They're checked after each run and offered for mapping in later steps. |
| Allow network | Off by default: the container has no network at all. |
| Time limit, memory | The most a step may use. A step can ask for less, never more. |
| Worker pools | The pools allowed to run the package. At least one. |
To ship a new version, push the new image and change the digest on the package. Steps keep using the package, so they pick up the new digest on their next run.
Use a package in a workflow
- Add the Code package step and pick a package. The step shows Runs only on your worker pool.
- Fill in the inputs. Expressions such as
{{ $nodes.Webhook.body.pages }}work. Values are converted to the input's type, so"3"becomes3for a number input. - Optionally pass files (e.g.
{{ $nodes['Load File'] }}or a list of files), and lower the time or memory limit.
Before a run, the editor's checks report an error on the step when:
- the project (or one of its environments with its own pool) runs on hosted workers: route it to a worker pool under Settings → Workers;
- it runs on a pool the package doesn't allow: an admin can add the pool on the package;
- the package was deleted.
The same rules are enforced when the step runs, whatever the editor showed.
Where packages never go
- Hosted workers never run a package. A step that lands there fails with a message saying so.
- Other workspaces. A package belongs to one workspace. A building block that contains a Code package step can only be private. Publishing or switching it to organisation or public is refused.
- The community catalogue. Packages aren't apps or templates and can't be published there.
Turn it on for a worker
Registering a package in Blokkio is never enough on its own. The worker has the last word: it runs a package only when the person who runs the worker turned code packages on and listed the image's registry. Blokkio can't make a worker run an image.
| Setting | Default | Meaning |
|---|---|---|
Worker__CodePackages__Enabled | false | Run code packages on this worker. |
Worker__CodePackages__AllowedRegistries__0, __1, … | (none) | Registries this worker pulls from: a host (registry.example.com) or a host plus a repository prefix (ghcr.io/acme). docker.io is Docker Hub. |
Worker__CodePackages__AllowNetwork | true | false runs every package without network, even when its admin allowed network. |
Worker__CodePackages__MaxTimeoutSeconds | 900 | Upper bound for any package's time limit on this worker. |
Worker__CodePackages__MaxMemoryMb | 2048 | Upper bound for any package's memory limit. |
Worker__CodePackages__Cpus | 1 | CPUs per package container (--cpus). |
Worker__CodePackages__PidsLimit | 256 | Most processes per package container (--pids-limit). |
Worker__CodePackages__MaxOutputMb | 10 | Largest stdout (output JSON) accepted. |
Worker__CodePackages__MaxFilesMb | 200 | Largest total size of files passed in, and of files returned. |
Worker__CodePackages__MaxOutputFiles | 50 | Most files returned from /work/out. |
Worker__CodePackages__DockerCommand | docker | The Docker CLI to run. DOCKER_HOST selects the engine as usual. |
A worker with code packages on shows code-packages in its capabilities under Settings → Workers.
Give the worker a Docker engine
The worker image includes the Docker CLI. It starts package containers on a Docker engine you give it, in one of these ways:
-
Mount the Docker socket (simplest). In the Portainer worker stack uncomment:
environment:Worker__CodePackages__Enabled: "true"Worker__CodePackages__AllowedRegistries__0: ghcr.io/your-orgvolumes:- /var/run/docker.sock:/var/run/docker.sockgroup_add:- "${DOCKER_GID:-999}" # stat -c %g /var/run/docker.sockThe worker runs as a non-root user, so it needs the socket's group (
group_add). -
A remote or rootless engine: set
DOCKER_HOST(e.g.tcp://docker-host:2376with TLS, or a rootless socket) instead of mounting/var/run/docker.sock. -
Private registries: log in on the engine host, or mount a Docker
config.jsonwith credentials into the worker and setDOCKER_CONFIGto its folder.
Images are pulled on first use and then reused. Because images are pinned by digest, a cached image is always the approved one.
:::warning Security: the Docker socket is root access
Whoever can talk to the Docker engine can start a privileged container and take over the host. Mounting
/var/run/docker.sock gives the worker that power. Blokkio limits what it asks Docker to do (see below), but if
the worker container itself is compromised, the host is too. So:
- Run code-package workers on a machine or VM dedicated to them, not next to your databases.
- Prefer rootless Docker, or a socket proxy that only allows the container calls the worker makes
(
images,containerscreate/start/attach/archive/inspect/kill/delete). - Keep AllowedRegistries narrow (
ghcr.io/your-org, notghcr.io), and restrict who can push there. - Leave network off for packages that don't need it, or set
Worker__CodePackages__AllowNetwork=false. :::
What the worker asks Docker for
Each run is docker create + docker cp (the work folder in) + docker start --attach --interactive +
docker cp (/work/out back) + docker rm --force, with:
--network none(or the default bridge only when network is allowed),--memoryand--memory-swapset to the limit,--cpus,--pids-limit,--cap-drop ALLand--security-opt no-new-privileges,--log-driver none, so the package's output never lands in Docker's logs,--pull never(the image is pulled by digest beforehand), and no volumes or bind mounts.
Files are copied in and out (docker cp) instead of bind-mounted, so the same setup works when the worker
itself runs in a container. The container is always removed, also after a timeout or a crash.
Why the Docker CLI and not the Docker Engine API? The CLI already speaks every way of reaching an engine
(the socket, DOCKER_HOST over TLS, rootless Docker, Docker-compatible engines such as Podman), streams stdin and
stdout, and uses your registry credentials. Doing this over the raw Engine API would mean reimplementing
attach streams and credential handling for no gain.
Troubleshooting
| The step says | What to do |
|---|---|
| …run only on your own worker pool, never on Blokkio's hosted workers | Route the project or environment to a pool under Settings → Workers. |
| The worker pool running this step isn't allowed to run … | An admin adds the pool to the package under Settings → Code packages. |
| This worker doesn't run code packages | Set Worker__CodePackages__Enabled=true on the worker. |
| This worker doesn't allow images from … | Add the registry to Worker__CodePackages__AllowedRegistries. |
| …could not be started on this worker: the worker can't reach Docker | Mount the socket and add its group (group_add), or set DOCKER_HOST. |
| …the image could not be pulled | Check the digest and the worker's registry credentials. |
| …what it printed on stdout isn't JSON | Print only the result on stdout; send logs to stderr. |
| …returned output that doesn't match its output fields | Return the fields with the types registered on the package. |