Skip to content

fix(modal_vm): send an exec's argv over stdin past Modal's exec limit - #906

Open
sarah-chitty-1 wants to merge 4 commits into
mainfrom
sarahchitty/sandbox-batch-image-loads
Open

sarah-chitty-1 wants to merge 4 commits into
mainfrom
sarahchitty/sandbox-batch-image-loads

Conversation

@sarah-chitty-1

@sarah-chitty-1 sarah-chitty-1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem. Sandbox._load_docker_images puts every image's curl <signed URL> … | docker load into one bash -c script. 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:

modal.exception.InvalidError: Total length of CMD arguments cannot exceed 65536 bytes (ARG_MAX). Got 86204 bytes.

The deploy fails before anything starts. The same env with 14 images deploys fine.

Fix. ModalVmSandbox.exec sends an argv longer than _MAX_EXEC_ARG_BYTES (32 KiB) over stdin instead: it runs bash -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 (bash or sh) -c script to a temp file and evals it from there (removing the file first), keeping its $0 and $@; 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, and Sandbox._load_docker_images is 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 -c script runs with its $0 and $@ 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 KiB python3 -c keeps its own source. 33 passed, 3 skipped locally.

Found deploying psi-person-d8e7d7228a-multi v5 for a PSI-Bench task.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence 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.

  • Long Modal VM commands now run without oversized exec arguments.

Reviews (8) · Last reviewed commit: "fix(modal_vm): move only a shell's -c sc..." · Reviewed by Greptile

…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>
@sarah-chitty-1
sarah-chitty-1 requested a review from a team as a code owner November 24, 2026 03:56
# 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@sarah-chitty-1 sarah-chitty-1 changed the title fix(sandbox): load docker images in batches under the exec argument limit fix(modal_vm): send an exec's argv over stdin past Modal's exec limit Nov 24, 2026
… 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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants