Repository navigation
fix(modal_vm): send an exec's argv over stdin past Modal's exec limit - #906
sarah-chitty-1 wants to merge 4 commits into
Conversation
…imit _load_docker_images ran every image's curl-of-a-signed-URL in one bash -c script. Signed URLs with a session token are ~2.4 KB each, so a MultiEnv with 36 images (14 MCP servers and 11 websites, two images each) made an 86 KB script and Modal's VM sandbox refused it: "Total length of CMD arguments cannot exceed 65536 bytes (ARG_MAX)". The loads now go in scripts of at most 60,000 bytes, each in parallel and the scripts one after another. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| # per image, run in parallel in one `bash -c` script, and a provider caps one exec's arguments: Modal's VM sandbox at | ||
| # 65536 bytes (ARG_MAX). A MultiEnv with many images (14 MCP servers and 11 websites, two images each) passes that, so | ||
| # the loads go in batches under this size, each batch in parallel and the batches one after another. | ||
| _MAX_LOAD_SCRIPT_BYTES = 60_000 |
There was a problem hiding this comment.
🤖 Drafted by Claude Code, reviewed by Edgar Arakelyan before posting.
The 64 KiB cap is Modal VM's exec limit, so could the fix live in ModalVmSandbox.exec instead of Sandbox? kosa8 already routes a command past its argv limits through a file (_FROM_FILE); Modal VM could send it over stdin the same way (mapfile -d "" -t a && exec "${a[@]}"). That keeps all of a big env's loads in parallel, covers any other long exec on modal_vm, and leaves the shared load path as it was for every other provider.
There was a problem hiding this comment.
Good call, moved it. ModalVmSandbox.exec now sends any argv over 32 KiB over stdin (mapfile -d "" -t a && exec "${a[@]}" </dev/null, NUL-separated, written in drained pieces), and the Sandbox batching is reverted, so the shared load path is back to main and all loads stay parallel. 49e4577
Moves the fix from Sandbox (batched image loads) into ModalVmSandbox.exec, per review: an argv past 32 KiB is written NUL-separated to stdin and read back with mapfile, as kosa8 does through a file. Every image load stays parallel, any long exec on modal_vm is covered, and the shared load path is unchanged for other providers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… argument limit Addresses Greptile: over stdin the argv dodged Modal's limit, but exec still passed a -c script as one argument, which Linux caps at 128 KiB (MAX_ARG_STRLEN). The wrapper now writes the script to a temp file and evals it from there, removing the file first, so $0 and $@ are kept. Tested with a 200 KiB script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Greptile: the wrapper rewrote any -c, so a long python3 -c got the eval as its source. Only bash or sh (by basename) has its -c script run from a file now; another program's arguments go through unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem.
Sandbox._load_docker_imagesputs every image'scurl <signed URL> … | docker loadinto onebash -cscript. Each signed S3 URL carries a session token and runs about 2.4 KB, so the script grows by that much per image. A MultiEnv with 36 images (14 MCP servers, plus 11 websites with a backend and a frontend each) produced an 86 KB script, and Modal's VM sandbox refused the exec:The deploy fails before anything starts. The same env with 14 images deploys fine.
Fix.
ModalVmSandbox.execsends an argv longer than_MAX_EXEC_ARG_BYTES(32 KiB) over stdin instead: it runsbash -c 'mapfile -d "" -t a && exec "${a[@]}" </dev/null'and writes the argv NUL-separated, in drained 32 KiB pieces, the way kosa8 routes a command past its argv limits through a file (_FROM_FILE). Linux also caps a single argument at 128 KiB (MAX_ARG_STRLEN), so the wrapper writes a shell's (bashorsh)-cscript to a temp file and evals it from there (removing the file first), keeping its$0and$@; another program's-c(python3, say) goes through unchanged. Every image load stays in one parallel script, any other long exec on modal_vm is covered too, andSandbox._load_docker_imagesis unchanged for every other provider. Shorter execs go out as argv exactly as before.Tests.
modal_vm_sandbox_test.py: a 36-image load script (about 86 KB) goes through the stdin wrapper with the argv intact and every write under the limit; the wrapper itself round-trips an argv with spaces, quotes and newlines through real bash, and a 200 KiB-cscript runs with its$0and$@and leaves no temp file (both need bash 4.4+, so they skip on macOS's 3.2; checked by hand on Ubuntu 24.04's bash 5.2, where the previous wrapper fails with "Argument list too long"). A 40 KiBpython3 -ckeeps its own source. 33 passed, 3 skipped locally.Found deploying
psi-person-d8e7d7228a-multiv5 for a PSI-Bench task.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issue was found.Summary
The PR sends long commands over stdin to bypass Modal’s argument limit.
Reviews (8) · Last reviewed commit: "fix(modal_vm): move only a shell's -c sc..." · Reviewed by Greptile