Skip to content

fix(sandbox): pass args and stdin to Docker containers - #47

Merged
dwisiswant0 merged 2 commits into
mainfrom
dwisiswant0/fix/sandbox/pass-args-and-stdin-to-docker-containers
Nov 4, 2026
Merged

dwisiswant0 merged 2 commits into
mainfrom
dwisiswant0/fix/sandbox/pass-args-and-stdin-to-docker-containers

Conversation

@dwisiswant0

Copy link
Copy Markdown
Member

EvalWithVirtualEnv with VirtualEnvDocker gave the container only the
source text and an interpreter. The call args, Options.Args and the
input source never reached it, so a script that Eval runs as "engine
Options.Args script args < input" ran in Docker with no arguments, no
interpreter flags and no stdin.

SandboxDocker.RunSourceWithOptions now takes interpreter args, script
args and a stdin reader, and EvalWithVirtualEnv passes all three. The
arguments reach the container as positional parameters of the wrapper
shell, which execs "$@", so the shell never parses them. Stdin is
attached before the container starts and closed once the input is
copied. RunSource keeps its behavior, and a source with a shebang still
runs directly.

A second commit splits runCommand into containerConfig, hostConfig and
collectResult, and removes the container with one deferred call instead
of a copy on every exit path. Behavior is unchanged.

The tests run the same source through Eval and through
EvalWithVirtualEnv against a stub Docker Engine API and compare the
output and exit code, so they don't need a daemon.

Fixes: #46

EvalWithVirtualEnv with VirtualEnvDocker gave the container only the
source text and an interpreter. The call args, Options.Args and the
input source never reached it, so a script that Eval runs as "engine
Options.Args script args < input" ran in Docker with no arguments, no
interpreter flags and no stdin.

SandboxDocker had no way to take them: RunSource accepted only the
source and an interpreter, and the container was created without
stdin. RunSourceWithOptions also takes interpreter args, script args
and a stdin reader, and EvalWithVirtualEnv passes all three. The
arguments reach the container as positional parameters of the wrapper
shell, which execs "$@", so the shell never parses them. Stdin is
attached before the container starts and closed once the input is
copied. RunSource keeps its behavior, and a source with a shebang
still runs directly, without the interpreter and its args.

runCommand loses its unused createFile and fileContent parameters.

Fixes: #46
Signed-off-by: Dwi Siswanto <git@dw1.io>
runCommand built the container and host configs, ran the container
and read its logs in one function, and repeated the container
removal on every exit path. The configs and the log reading move to
containerConfig, hostConfig and collectResult, and one deferred call
removes the container, so a new exit path can't skip the cleanup.

The empty-command error becomes a sentinel, the environment slice is
preallocated, and the log buffer size is a named constant. Behavior
is unchanged.

Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
dwisiswant0 requested a review from Mzack9999 November 4, 2026 06:20
@dwisiswant0
dwisiswant0 merged commit 193f003 into main Nov 4, 2026
4 checks passed
@dwisiswant0
dwisiswant0 deleted the dwisiswant0/fix/sandbox/pass-args-and-stdin-to-docker-containers branch November 4, 2026 08:54
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.

EvalWithVirtualEnv (Docker) drops args, Options.Args and stdin

2 participants