dr-docker
Reusable Docker execution contracts and adapters.
Purpose
This repo provides Docker runtime contracts and a concrete subprocess adapter:
- Docker runtime request/result contracts with security and resource profiles
- Runtime adapter protocol
- Subprocess-based Docker adapter with stream capping and cidfile cleanup
- Worker helpers for mounted scripts/directories with reusable runtime policies
- Typed error envelopes
Public Surface
from dr_docker import (
CONTRACT_VERSION,
DockerMount,
DockerRuntimeRequest,
DockerRuntimeResult,
ErrorCode,
ErrorEnvelope,
MountedWorker,
ResourceLimits,
RuntimeAdapter,
RuntimePrimitiveError,
SecurityProfile,
SubprocessDockerAdapter,
TmpfsMount,
WorkerRuntimePolicy,
__version__,
build_mounted_worker_request,
execute_batch_in_container,
mount_worker_directory,
mount_worker_file,
run_batch_with_failure_isolation,
)
Worker Support
dr-docker now includes a small worker-support layer for the common pattern of:
- starting from a reusable isolated runtime policy
- mounting a local worker file or directory into the container
- building a
DockerRuntimeRequestwith stdin, env, mounts, tmpfs, and resource limits already wired together
from pathlib import Path
from dr_docker import (
JsonWorkerExecutionConfig,
WorkerRuntimePolicy,
build_mounted_worker_request,
mount_worker_file,
parse_byte_size,
)
worker = mount_worker_file(Path("worker.py"), mount_target="/sandbox")
worker = worker.with_path_command(
entrypoint="python3",
args_before_path=["-I"],
working_dir="/tmp",
)
policy = WorkerRuntimePolicy.small_isolated().with_env_overrides().model_copy(
update={"memory": "1g", "tmpfs_exec": True}
)
worker_config = JsonWorkerExecutionConfig.from_runtime_policy(
policy,
timeout_seconds=30,
)
request = build_mounted_worker_request(
image="python:3.12-slim",
worker=worker,
timeout_seconds=30,
policy=policy,
stdin_payload='{"job": "ping"}',
env={
**worker_config.to_env(),
"WORKER_MODE": "json",
},
)
For optional worker-side JSON-over-stdin helpers, use dr_docker.workers.json_stdio. That module intentionally stays separate from the core Docker contract layer and includes bounded stdin reading, bounded stdout capture, container guards, and basic RLIMIT helpers.
For reusable size parsing, use parse_byte_size("1.5g").
Contract Guarantees
DockerRuntimeResult(ok=False)requireserror- Successful result envelopes must not include
error - Error envelopes are typed (
ErrorCode) with non-empty message and JSON-safe details - Supported
ErrorCodevalues aretimeout,unavailable, andinternal_error
Development
uv sync --group dev
uv run pytest -q
uv run ruff format --check
uv run ruff check
uv run ty check
Publishing
cp .env.example .env
# set PYPI_API_TOKEN in .env
set -a; source .env; set +a
uv build
uvx twine check dist/*
uvx twine upload -u __token__ -p "$PYPI_API_TOKEN" dist/*
Metadata
Release files for dr-docker 0.4.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dr_docker-0.4.5.tar.gz | 54.1 kB | Without provenance | Details for dr_docker-0.4.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dr_docker-0.4.5-py3-none-any.whl | Python 3 | none | any | Details for dr_docker-0.4.5-py3-none-any.whl |
Total release size: 75.8 kB
Release files / dr_docker-0.4.5.tar.gz
| Download URL | dr_docker-0.4.5.tar.gz |
|---|---|
| Size | 54.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2ee6aba4297de97e3c679137e41b647939ff9e8b164682369a608e955485146
|
|
BLAKE2b-256 checksum How to use checksums |
513a4d2d113d7b1cd15c60ce0f3cf52679647609630ee714b3e9f82a9f0a839b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.0
|
Release files / dr_docker-0.4.5-py3-none-any.whl
| Download URL | dr_docker-0.4.5-py3-none-any.whl |
|---|---|
| Size | 21.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e268eb7c69ead188ecdec021f2b853e01741e626f99a00748953ebb6e42b753
|
|
BLAKE2b-256 checksum How to use checksums |
34080d6e873c862c136f6a86f2c4ae66116036eaf3367ab6c83c3dec630ff9c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.0
|
Security for dr-docker 0.4.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.