agentleFS
gp201gp201/agent-skills/skills/podman-runner/SKILL.md

podman-runner

Skill2 starsChanged 7 months agoApache-2.0View on GitHub

Use when the user wants to run an experiment script, command, or pipeline step inside a reproducible container — phrases like "run this in a container", "containerize this run", "execute train.py under podman", "reproduce this run". Handles the Containerfile, build, GPU passthrough, log capture, and `runs/<id>/` provenance. Do not invoke for local-only dev loops or for production deployments.

  • Deletes or force-pushes
  • Installs packages

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. About 0 are common, 6 are distinctive, and 11 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If the user hasn't set this up, fall back to CPU and flag it.

    line 36
  2. Distinctive:

    If the working tree is dirty, append a warning.

    line 54
  3. Very specific:

    If the project has an empty Containerfile, populate it with this and ask the user to confirm before the first build:

    line 76
  4. Very specific:

    Do not bake data/ or secrets into the image.

    line 102
  5. Distinctive:

    Before claiming a run used the GPU, verify:

    line 168
  6. Distinctive:

    If any step fails, drop GPU flags and surface a warning in the run README.

    line 176
  7. Distinctive:

    When the user says "reproduce run X":

    line 181
  8. Very specific:

    Read runs/X/git.txt — check out that commit (or warn if dirty).

    line 183
  9. Very specific:

    Read runs/X/config.yaml — pass it verbatim to the script.

    line 184
  10. Very specific:

    Read runs/X/cmd.txt — use the same command.

    line 185
  11. Very specific:

    Run id and absolute path to runs/<id>/.

    line 194
  12. Very specific:

    Don't run sudo podman. Rootless podman is the default.

    line 201
  13. Very specific:

    Don't mount ~ or / into the container.

    line 203
  14. Distinctive:

    Don't delete a run directory on failure.

    line 205
  15. Very specific:

    Don't skip provenance "because it's just a test run".

    line 206
  16. Very specific:

    Don't invent metrics the script didn't produce.

    line 209
  17. Very specific:

    Don't use --privileged, --cap-add=ALL, or disable SELinux labels (:z / :Z are fine.

    line 211

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

podman-runner

Single entry point for executing experiment commands inside a podman container. The skill guarantees the command runs in a reproducible environment, captures logs, and writes a provenance-complete runs/<id>/ directory matching the layout in experiment-structure.

When to use

  • The user asks to run a script or command and reproducibility matters: "train the model", "run the sweep", "reproduce run 2026-03-10-lr-sweep".
  • A new experiment has just been scaffolded (experiment-structure) and the Containerfile is empty.
  • CI or a teammate will need to run the same command on another machine.

Skip this skill for:

  • quick interactive debugging loops (just run the script directly),
  • deploying a service (use a proper orchestration tool),
  • commands that don't produce artifacts worth preserving (e.g. ruff check).

Prerequisites (assumed, not installed by this skill)

  • podman on PATH (podman --version works). If not, stop and ask the user to install it; don't shell out to apt/dnf.
  • For GPU work: nvidia-container-toolkit configured for podman, and podman run --device nvidia.com/gpu=all succeeds on a probe image. If the user hasn't set this up, fall back to CPU and flag it.
  • A project laid out by experiment-structure (or at least a Containerfile and a scripts/ entry point).

The contract

Given a command like python scripts/train.py --config configs/base.yaml, this skill:

  1. Builds (or rebuilds, if Containerfile changed) an image tagged <project>:<short-git-hash>.
  2. Generates a run id (YYYY-MM-DD-HHMM-<slug>) and creates runs/<id>/.
  3. Writes provenance files into the run directory before launching the container:
    • config.yaml — the fully-resolved config (substitute all ${var} references and merged overrides).
    • git.txt — git rev-parse HEAD + git status --porcelain. If the working tree is dirty, append a warning; do not block.
    • env.txt — image digest + pip freeze captured from inside the image.
    • cmd.txt — the exact command as invoked, plus the podman flags used.
  4. Runs the container with:
    • --rm (no leftover containers),
    • -v $(pwd):/workspace:z (bind-mount the repo; :z for SELinux),
    • -w /workspace,
    • --device nvidia.com/gpu=all when GPUs are requested and available,
    • -e PYTHONUNBUFFERED=1 so logs stream,
    • stdout → runs/<id>/logs/stdout.log (via tee for live view),
    • stderr → runs/<id>/logs/stderr.log,
    • exit code captured into runs/<id>/exit_code.
  5. On success: writes a small runs/<id>/README.md stub ("Started at …, finished at …, command: …, exit code: 0").
  6. On failure: does not delete the run directory — the partial artifacts and logs are the debugging trail.

Containerfile starter

If the project has an empty Containerfile, populate it with this and ask the user to confirm before the first build:

FROM python:3.11-slim

# System deps: add only what the experiment actually needs
RUN apt-get update && apt-get install -y --no-install-recommends \
      git build-essential \
    && rm -rf /var/lib/apt/lists/*

# Python deps: install pinned requirements separately from source
# so the cache survives edits to src/.
WORKDIR /workspace
COPY pyproject.toml ./
RUN pip install --no-cache-dir -e .

# Source is bind-mounted at runtime; no COPY . .

For GPU workloads swap the base image for one of:

  • nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04 (runtime only),
  • pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime (if PyTorch is the primary framework), and pip install torch against the matching CUDA build.

Do not bake data/ or secrets into the image. Data is bind-mounted; secrets come from --env-file at run time.

Running a command

Minimum invocation:

podman run --rm \
  -v "$(pwd):/workspace:z" \
  -w /workspace \
  <project>:<tag> \
  python scripts/train.py --config configs/base.yaml

This skill wraps that with provenance capture. Pseudocode for the runner flow (implement inline — don't require a helper script):

run_id = f"{datetime.now():%Y-%m-%d-%H%M}-{slug}"
run_dir = Path(f"runs/{run_id}")
run_dir.mkdir(parents=True)

# 1. Resolve config
resolved = merge_config(base="configs/base.yaml", override=args.config)
(run_dir / "config.yaml").write_text(yaml.safe_dump(resolved))

# 2. Provenance
subprocess.run(["git", "rev-parse", "HEAD"], stdout=(run_dir/"git.txt").open("w"))
subprocess.run(["git", "status", "--porcelain"], stdout=(run_dir/"git.txt").open("a"))
(run_dir / "cmd.txt").write_text(" ".join(shlex.quote(a) for a in full_cmd))

# 3. Build image (cached if Containerfile unchanged)
tag = f"{project}:{git_short_hash}"
subprocess.run(["podman", "build", "-t", tag, "."], check=True)

# 4. Capture env from inside the image
subprocess.run(
    ["podman", "run", "--rm", tag, "pip", "freeze"],
    stdout=(run_dir/"env.txt").open("w"), check=True,
)

# 5. Run
gpu_flags = ["--device", "nvidia.com/gpu=all"] if gpu_available() else []
cmd = [
    "podman", "run", "--rm",
    "-v", f"{os.getcwd()}:/workspace:z",
    "-w", "/workspace",
    "-e", "PYTHONUNBUFFERED=1",
    *gpu_flags,
    tag,
    *user_cmd,
]
proc = subprocess.run(
    cmd,
    stdout=(run_dir/"logs/stdout.log").open("w"),
    stderr=(run_dir/"logs/stderr.log").open("w"),
)
(run_dir / "exit_code").write_text(str(proc.returncode))

For live log viewing, wrap each stream with tee or Python's subprocess.Popen + threaded line-reader; don't swallow output.

GPU passthrough — quick checklist

Before claiming a run used the GPU, verify:

  1. Host: nvidia-smi works.
  2. Podman: podman run --rm --device nvidia.com/gpu=all \ nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi shows the GPU.
  3. Inside the experiment image: add a boot-time sanity check that logs torch.cuda.is_available() (or equivalent) to runs/<id>/logs/stdout.log.

If any step fails, drop GPU flags and surface a warning in the run README. Never silently fall back; the user needs to know.

Reproducing a prior run

When the user says "reproduce run X":

  1. Read runs/X/git.txt — check out that commit (or warn if dirty).
  2. Read runs/X/config.yaml — pass it verbatim to the script.
  3. Read runs/X/cmd.txt — use the same command.
  4. Build the image at that commit (tag will differ; that's expected).
  5. Execute into a new runs/<new-id>/ — never overwrite.
  6. Diff runs/X/metrics.json against runs/<new-id>/metrics.json and report exact-match, within-tolerance, or divergent.

Output

Report to the user:

  • Run id and absolute path to runs/<id>/.
  • Exit code and wall-clock time.
  • Headline numbers from metrics.json (if present).
  • Any warning: dirty git tree, CPU fallback, non-zero exit.

What not to do

  • Don't run sudo podman. Rootless podman is the default; if rootless fails, surface the error rather than escalating.
  • Don't mount ~ or / into the container. Mount the project directory only.
  • Don't delete a run directory on failure. The logs are the point.
  • Don't skip provenance "because it's just a test run". Every run writes git.txt, env.txt, config.yaml, cmd.txt. No exceptions.
  • Don't invent metrics the script didn't produce. If the script didn't write metrics.json, the run has no metrics — say so.
  • Don't use --privileged, --cap-add=ALL, or disable SELinux labels (:z / :Z are fine; --security-opt label=disable is not).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.