Repository navigation
Description
What's missing
spawn app launch --image can run a BYO container from ECR, but it comes with the app
catalog and NICE DCV (spawn app is "Launch and manage catalog applications via NICE
DCV"). spawn launch and spawn service have --ami, --user-data and --command, but
no --image.
So there's no way to say "run this container image as the workload" on a plain launch.
Why I need it
foray (github.com/scttfrdmn/foray) runs an nnsight worker on a per-session GPU. Two
paths launch it:
spawn service … -- env … python3 -m worker.serve # interactive, tunnelled
spawn launch --command 'env … python3 -m worker.batch' # one-shot, headless
Both assume the worker package is on the instance. It isn't — the auto-detected AL2023
AMI has python3 but no worker, no torch, no nnsight. The worker already ships as a
single container image holding both serving engines, so --image is exactly the missing
link. Tracked on foray's side as
foray#103.
The workload is headless: an HTTP API for a control plane, no browser, no streaming
desktop. Going through spawn app would mean carrying DCV and a catalog binding for
something that has no UI at all.
What would help
--image on spawn launch and/or spawn service, meaning "pull this image and run it as
the workload", with --command/args applying inside the container. The pieces seem to
exist already for spawn app — image pull, ECR auth on the instance role, spored
supervising the container — so this may be mostly a matter of exposing that path without
the catalog/DCV layer.
Two details that matter for my case, though I don't want to over-specify:
- Host networking, or an equivalent.
spawn serviceforwards to a loopback port the
workload announces. A container on a bridge network binds the container's loopback, not
the host's, so the forward can't reach it.--network hostis what makes
spawn service --imagecoherent. - ECR pull permissions. Whatever role the instance gets needs them; for
spawn app
that's presumably already handled.
Alternatives I considered
- Bake an AMI (
spawn ami create). Works, fastest boot, but it's a build artifact to
maintain and version per region for something that already has an image. - Upload a tarball and pip install at boot.
spawn service --uploadtakes one file,
and installing torch/nnsight/vllm on every launch would add minutes of GPU time per
session — the expensive direction. spawn app launch --image --web-port. Closest existing fit, and it even gives a
TLS endpoint with an access token, which is neat. But it's the DCV/catalog path for
something with no UI, and the token-fronted endpoint is a capability I specifically
designed around (foray hands work over via S3 precisely so nothing inbound is needed).
Happy to be told the spawn app --image path is the intended answer and I should use it —
in which case a note in spawn launch --help pointing there would have saved me the
search.
Activity
scttfrdmn commentedon Sep 26, 2026
Withdrawing most of this — the capability exists and I missed it.
spawn task runwith a task spec already does what I asked for, and more:```json
{
"command": ["python3", "-m", "worker.batch"],
"container": "…dkr.ecr….amazonaws.com/foray-worker:dev",
"resources": { "instance_type": "g7e.xlarge", "purchase": "spot" },
"inputs": [{ "source": "s3://…/graph.json", "destination": "/tmp/graph.json" }],
"outputs": [{ "source": "/tmp/result.json", "destination": "s3://…/result.json" }],
"lifecycle": { "ttl": "2h", "on_complete": "terminate", "cost_limit": 0.50 }
}
```
That is foray's data plane almost exactly — container delivery, S3 stage-in/stage-out,
a pinned instance type, terminate-on-complete, and a cost ceiling. I had hand-rolled the
S3 staging myself and never found the container path. Reading
scientific-codes-cookbook's
practices/container-path.mdis what surfaced it.
What I'd still find useful, much narrower than the original ask:
spawn servicehas no container path.serviceis the long-lived-HTTP-plus-tunnel verb,and its workload has the same delivery problem
task runsolves — right nowspawn service … -- python3 -m worker.serveassumes the code is already on the box, andthere's no way to say "serve this image".
--imageonservice(with host networking, sothe announced loopback port is reachable through the forward) would close that.
Not urgent for me: foray's page path is moving to
task run, and the CLI's interactivetunnel can bake an AMI or use
--uploadin the meantime.Also worth a doc nudge:
spawn launch --helpandspawn service --helpdon't mentiontask runas the container path. I went looking for--imageon both, found it only underspawn app(which is DCV/catalog-shaped and wrong for a headless worker), and concluded noplain-container path existed. A one-line pointer would have saved that.
Happy for this to be closed or retitled to the
service --imageslice — your call.scttfrdmn commentedon Sep 26, 2026
The guess in the issue — "the pieces seem to exist already" — is right, and more so than it assumes. Both pieces exist, but in two separate places, neither reachable from
launch/service:--imageneedsdocker run, private-ECR auth,--gpus all+ NVIDIA Container Toolkit setuppkg/taskproto/wrapper.go— thespawn task runwrapper (ecrImageAccount, the--gpus allgating from #606)docker run --rm … --network hostcmd/app.go:586— thespawn app launchcontainer pathSo spawn already carries two independent
docker rungenerators, built for different purposes, with overlapping concerns (image pull, ECR auth, GPU flags, volume mounts, host networking).Which reframes this issue
Adding
--imagetolaunchandserviceby writing a third container-run generator would be the wrong shape — three copies of ECR auth and GPU-flag logic, drifting independently. #606 is the cautionary case:--gpus allhad to be fixed in the task wrapper, and nothing structurally guarantees the app path or any future path got the same treatment.The better framing is extraction, not addition: pull one container-run builder out of the two existing call sites — image reference + ECR auth, optional
--gpus all(+ toolkit install), volume mounts, network mode, user mapping, and the command/args to run inside — then havetask run,app launch, and a newlaunch/service --imageall use it. That answers this issue as a side effect of removing duplication, rather than growing the surface.It also settles the two details raised here without needing new design:
--network hostalready exists on the app path and becomes a parameter of the shared builder (and is the right default forservice --image, sinceserviceforwards to a loopback port the workload announces, which a bridge network would hide); ECR pull permissions are already handled on the task path and come along with it.One question before any of that
Your one-shot headless case may already be served today:
spawn task runruns a container image headlessly, with GPU support and results staged to S3, which is close to what that line is trying to do. If it doesn't fit, knowing why would sharpen this issue — I'd guess the spec-file indirection and the S3 results convention don't suit a control plane that already hands work over via S3 itself, but that's a guess. If it does fit, the gap narrows to the long-runningservicecase, which genuinely has no equivalent today, and that's a smaller and clearer ask.On the closing offer in the issue — no,
spawn app launch --imageis not the intended answer for a headless workload. Reaching it means carrying a catalog binding and DCV for something with no UI, and the token-fronted TLS endpoint is a capability you deliberately designed around. Either wayspawn launch --helpshould point somewhere useful for "run this container", which it currently doesn't.scttfrdmn commentedon Sep 26, 2026
Answering the question directly: yes,
task runfits — and better than what I builtYour guess was that the spec-file indirection and the S3 results convention wouldn't suit a
control plane that already hands work over via S3. I went and checked the wrapper rather than
reason about it, and the opposite is true on both counts.
1.
inputsstaging removes a race I had to engineer around. foray's graph key contains theinstance id, so the control plane can only write
graph.jsonafter launching — which means myworker polls for its own input for up to 120s, purely to close the window where it boots faster
than the write lands.
task runstages inputs before the container execs, so that wait becomesdead code and the worker reads a local file. It also stops needing boto3 for the handoff at all.
2. The completion record is the thing my design actually lacks.
pkg/taskproto/wrapper.gowrites
completion.jsonand.exitcodeto$RESULTS_PREFIXeven on non-zero exit — theset +eat line ~103 exists precisely so a failing command still produces them. My handoff hasno equivalent: the worker writes an error result itself, which covers a trace that fails but
not a container that never gets far enough to write anything (bad image, OOM during model
load). In that case my control plane polls an object that never appears, forever.
task runalready solves that, and I'd have had to build it.
3. Neither of my two migration worries survived checking.
resultsPrefixis a wrapper parameter (wrapper.go:111), not a fixed convention — so theresult and the completion record can land in foray's own
sessions/<id>/layout, whereCollectalready looks. No second prefix to read.spawn taskis explicitly instance-shaped — "Work with a single launched instance as atask", with
instance_idin its output. foray's session id is the instance id, and thatmodel survives intact. This was my main concern and it's a non-issue.
So the one-shot headless case is served today, and
task runsubsumes four things foray builtby hand: the S3 handoff,
LaunchSpec.Command, explicit terminate at end-of-rung(
lifecycle.on_complete: terminate), and — as a second belt inside spawn — the per-session costceiling (
lifecycle.cost_limit). Tracked on my side asforay#103.
The gap narrows to
service --image, exactly as you said. That's the long-runninginteractive case with no equivalent, and I'm not blocked on it — the CLI tunnel can bake an AMI
or use
--uploadmeanwhile.On the extraction framing
Agreed, and #606 makes the argument better than any abstract DRY case:
--gpus allhad to befixed in the task wrapper, and nothing structurally guaranteed the app path got the same
treatment. A third generator would add a third place for that to diverge. From outside I can't
judge the refactor's cost, but the shape — one builder taking image + ECR auth + optional GPU
means
service --imageinherits GPU and ECR correctness rather than reimplementing it.The
--network hostpoint lands the same way: it's already on the app path, and it's not apreference for
servicebut a requirement, sinceserviceforwards to a loopback port theworkload announces and a bridge network hides exactly that.
Two things I'd still want, small
outputsdestinations from the CLI? Iverified the wrapper takes
resultsPrefixas a parameter; I did not verify whatspawn task runexposes. If the prefix is fixed at the CLI boundary, foray reads twolocations instead of one — workable, just worth knowing before I migrate.
/tmpflat-staging rule fromcontainer-path.mddeserves to be in
task run --help, not only the cookbook. The uid-1000-vs-container-usermismatch (and output parents created as root) means spawn's own
/data+/workexamplecannot work on that path — spawn task run: container can't write staged dirs when the image USER isn't root or uid 1000 (bioconda images are uid 57439) #555. I'd have walked straight into it; I only
didn't because you pointed me at the cookbook.
And agreed on the closing point:
spawn app launch --imageisn't the answer for a headlessworkload, and
spawn launch --helphaving some pointer for "run this container" would havesaved me filing this in the first place.
scttfrdmn commentedon Oct 3, 2026
Q1:
outputsyes, results prefix no — and the file:line above reads the wrong lineChecked rather than reasoned about, because the two halves of that question have opposite answers.
outputs[].destinationis fully caller-controlled, per object, to any bucket. Not just asettable prefix — each entry names its own destination, and they need not share a bucket or a
prefix with each other or with anything spawn picked. The mechanism that makes this work is
cmd/task.go:521: the launch role's inline policy is built froms3Buckets(spec.Outputs)(andspec.Inputs), so whatever buckets the spec names get write access granted at launch. Thecookbook is the standing proof — 79 recipes stage every output into a bucket spawn never chose
(
s3://cookbook-<account>-<region>/runs/<recipe>/…), alongside inputs from a third bucket andfrom RODA. So the "foray's own
sessions/<id>/layout" half of your plan works today, exactly asyou want it.
The completion record's prefix is not settable from the CLI. This is where the earlier comment
went wrong, and it's worth being precise since a migration decision hangs on it:
wrapper.go:111p("RESULTS_PREFIX=%s\n", shQuote(resultsPrefix))— only emits the value into the generated scriptwrapper.go:83resultsPrefix := fmt.Sprintf("s3://%s/tasks/%s", resultsBucket, taskID)— derives itcmd/task.go:471resultsBucket := fmt.Sprintf("spawn-results-%s-%s", account, region)— hardcodedresultsBucketis a parameter of the Go function, which is what line 111 looks like from theoutside; but the only caller computes it from account + region, and there is no override. The
complete flag set on
task runis--spec,--dry-run,--region,--ami,--wait,--poll-interval(cmd/task.go:1124-1129) — no results-bucket flag — and no env var either(nothing matches
SPAWN_RESULTS/results-bucketoutside tests).So: yes, foray reads two locations.
completion.jsonand.exitcodealways land ats3://spawn-results-<account>-<region>/tasks/<task_id>/completion.json; your results landwherever
outputssays. Worth noting that is not undocumented —task run --helpnames that pathliterally in its Long text — so it's a capability gap if you want it elsewhere, not a discovery
gap. Given
Collectalready has to poll something for the terminal signal, and the completionrecord is the one object guaranteed to appear even when the container never gets far enough to
write a result, a fixed well-known location for it seems like the lesser cost. But if a
results_prefixfield on the spec (or--results-prefix) would collapse it to one read, that's asmall and self-contained ask — happy to file it separately so this issue can narrow to
service --imageas you suggest.Q2: agreed, and two more that belong in the same paragraph
/tmpflat staging should be intask run --help. The current Long text says "the manifest dirsare bind-mounted", which is true and is exactly what led me to the same wrong conclusion the first
time — it reads as though any path works. Two facts are load-bearing and neither is in
--help:/tmpis the only mount writable whatever user the image runs as. Host/tmpis1777;stage-in runs as the instance user while the container runs as the image's user (bioconda
images are
mambauseruid 57439, conda-forge ones differ), so a 0755 directory owned by uid1000 is not writable. Two consequences that cost real debugging time: a directory output
cannot work on the container path, because output parents are never
mkdir-ed and dockerdcreates them as root (task: directory outputs (Manifest source ending in /) cannot work on the container path #564) —
tarthe directory to one flat file instead; and the containergets
EPERMunlinking a staged input it does not own, whichrm -fdoes not suppress (onlyENOENT), so it returns 1 and kills the task underset -e. That one killed two dependenttasks in a five-recipe batch, at the
rmof an index tar, after the science had alreadysucceeded.
/tmp, which is tmpfs sized at ½ instance RAM — notresources.disk_gib.disk_gibgrows the container root, so a spec asking for a 200 GiB diskto hold a 40 GiB staged index still fails at stage-in on a 32 GiB box. Measured: this is
routinely what picks the instance family rather than the size — a 32 GiB staging footprint put
one recipe on
m8g.2xlargeat 44% less than thec8g.4xlargethe vCPU count alone implied.Anyone sizing from
disk_gibsizes wrong.Both are in
practices/container-path.md,but you're right that the cookbook is the wrong only-home for them: they're properties of the
wrapper, not of scientific computing, and the person who needs them is reading
--help. Happy tosend that as a PR against the
Longtext if you'd rather not retitle this issue around it.scttfrdmn commentedon Oct 3, 2026
Both answers verified against the code rather than taken on trust — and your correction is right, so let me record that plainly first.
Q1 — you're right, and the earlier comment was wrong
resultsBucketis hardcoded atcmd/task.go:471andresultsPrefixis derived atwrapper.go:83; line 111 only emits the value. Confirmed there's no flag (--spec,--dry-run,--region,--ami,--wait,--poll-intervalis the whole set) and no env override. Reading line 111's parameter as caller-controlled was my error.And
outputs[].destinationdoes work exactly as you describe — per object, any bucket, granted at launch vias3Buckets(spec.Outputs)in the policy built atcmd/task.go:521.So: yes, two reads today. Filed as #646 with the shape you suggested (
results_prefixdefaulting to today's value), including the one argument against that I think is worth weighing —completion.jsonis the only object guaranteed to appear even when the workload never gets far enough to write a result, and since #632 it's also written when a lifecycle limit kills the task mid-command. A terminal signal at an unambiguous path independent of the spec has some value. Convenience trade, not a defect.Q2 — agreed, and I'll write it rather than ask you to
Both facts belong in
task run --help, and you've identified exactly why the current text misleads: "the manifest dirs are bind-mounted" reads as though any path works.Thanks for the PR offer, but I'll take this one — the
Longtext is the source fordocs-gen/, which is a hard CI gate (make check-docs), so it needs amake gen-docsin the same commit and that's an awkward thing to hand someone. Your two points go in close to verbatim; the tmpfs one especially, because "staging space is host /tmp sized at ½ RAM, notresources.disk_gib" is the kind of thing nobody deduces, and "sizes the instance family rather than the size" is the detail that makes it land.I'll cross-reference #564 (directory outputs) and #565 (sticky-
/tmpEPERMon unlink) from the help text instead of restating them, since both are open and the help shouldn't document a bug as a permanent property. Therm -fdetail is the sharpest part of that report — suppressingENOENTbut notEPERMis genuinely non-obvious, and "killed two dependent tasks after the science had already succeeded" is the right argument for prioritising #565.Narrowing this issue
Doing as you suggest. Retitling to
spawn service --image— the interactive, long-running path, which is the parttask rungenuinely doesn't cover. The one-shot half is withdrawn per your 2026-09-26 comment, and the docs work is tracked here until I open the PR.For the record of what this issue is now not:
spawn app launch --imageexists but carries the catalog and DCV, which is wrong for a headless HTTP worker; andtask runcovers one-shot containers. What's left is a supervised container on aservice-style instance with host networking.[-]Run a headless container image on launch/service (--image outside the app/DCV catalog)[/-][+]spawn service --image: run a supervised headless container on a long-running instance[/+]scttfrdmn commentedon Oct 4, 2026
Docs written: PR #649. But verifying your two points before writing them down turned up something better than a docs gap — both constraints have already been lifted, and documenting them would have baked obsolete advice into
--help.The uid mismatch is gone
#555(ac5655a, 2026-09-02) added--user "$(id -u):$(id -g)". It's evaluated in the same shell as stage-in, so the container runs as the instance user by construction — which also answers the objection in #565 that it "matches by luck of the AMI". It can't mismatch: the sameid -uthat owns the staged files is the one passed todocker run.#564 and #565 were fixed a month ago
Both by
c327274(2026-09-03), whose commit title names them: "create output-only mount dirs and fix staged-input ownership (#564, #565)".They still look open because PR #568 merged with no closing keyword in its body, so neither auto-closed. Same bookkeeping gap that left #615 open after #634. The fixes shipped; the issues didn't get updated.
Generated a wrapper with a directory output under a distinct parent to confirm, rather than trust the commit message:
So: directory outputs work (trailing slash →
--recursive, both directions), output-only parents are created as the invoking user so dockerd never gets to make them root-owned, and staged inputs are owned by the uid the container runs as — sormof a staged tar under sticky/tmpsucceeds.I'm not closing #564/#565 on a code read. You hit both on real instances, and #606 is the standing lesson here that real hardware catches what code-tracing misses. Next real run of one of those recipes would settle it.
What this means for the cookbook
practices/container-path.mdis now stricter than it needs to be. Two things are safe to drop: keeping staged paths flat in/tmp, and tarring a directory to one flat file. Any absolute path works and directory manifests stage recursively. Worth re-testing one recipe before you rewrite the guidance, given the above.The part that survived, and it's the better half
resources.disk_gibsizes the root EBS volume, so it's the knob for an ordinary path like/work./tmpis a tmpfs capped near half of instance memory — a 40 GiB index into/tmpfails on a 32 GiB box regardless ofdisk_gib. That's in--helpnow, including your point that sizing a staging footprint in memory tends to pick the instance family rather than its size (m8g.2xlargeat 44% under thec8g.4xlargethe vCPU count implied) — that's the detail that makes it land, and it's the one nobody deduces.With #555/#564/#565 resolved, the
/tmpconstraint was the consequence of the uid problem rather than a property of the wrapper — so the right advice is now close to the inverse of the workaround: stage big inputs to a non-/tmppath and sizedisk_gib.scttfrdmn commentedon Oct 4, 2026
Retracting half of my last comment — #564 is NOT fixed, and I was wrong
Do not rewrite
practices/container-path.mdyet. I told you the flat-/tmpworkaround was safe to drop. A real run says otherwise, and you were right the first time.I ran it on a real t4g.medium in 942542972736/us-west-2 — a directory output under an output-only parent, plus a staged input deleted from sticky
/tmpunderset -e. The two issues came apart:#565 is genuinely fixed — confirmed on real hardware
--userdoes override the image's declaredUSER(alpine declares root; the container ran as 1000), and the staged input is owned by that same uid, so the sticky-bit unlink succeeds. Therm -f/EPERMfailure that killed two of your recipes is gone.#564 is real and still open — my code read was wrong
The
mkdiris emitted — that part of my reading was right — but it runs as the unprivileged instance user, so it cannot create any directory whose parent it does not own. That is every top-level path:/out,/data,/work. Thendocker run -vauto-created the missing bind-mount source as root, mode 0755 — the exact failure your issue describes, and precisely what that loop exists to prevent.Worse, the host-side failure is silent: stage-in reported
rc=0, so the only symptom is a container permission error 90 seconds later with nothing pointing at the real cause.So:
/tmpreally is the only reliable staging location today, because it already exists and is 1777. Your cookbook guidance is correct as written, and spawn's own documented/data+/workexample cannot work — exactly as you said in your earlier comment, which I should have taken at face value instead of re-deriving it from the generated script.What I got wrong, and why
I concluded from
c327274's commit title ("create output-only mount dirs and fix staged-input ownership (#564, #565)") plus the emittedmkdir -pthat both were fixed. Both halves of that were misleading: the commit fixed the ownership half (#565) and added the mkdir for output-only parents, but the mkdir itself cannot succeed for a top-level path. A code read seesmkdir -p '/out/results'and stops; only a real instance shows it returning non-zero. This repo's #606 is the standing lesson on exactly that, and I repeated it.Consequences
sudo mkdir -pplus achownto the invoking uid — and only for directories that do not already exist, because chown'ing a pre-existing dir would be destructive (a destination of/tmp/fooyields a mount dir of/tmp, and chown'ing that would strip the sticky ownership the whole box depends on). A failure now setsSTAGE_RC, so the task fails at stage-in asstaging_errorrather than limping into an unwritable mount.#565 I will close once I have re-run it alongside the #564 fix. Cost of the run that found this: ~$0.002, instance terminated and leak-checked.
fix(taskproto): create bind-mount dirs with privilege, so top-level p…
fix(taskproto): create bind-mount dirs with privilege (#564), and doc…
chore(release): v0.117.0