Skip to content

dagger shell improvements - #14291

Merged
shykes merged 9 commits into
mainfrom
shell-exec-command
Sep 22, 2026
Merged

shykes merged 9 commits into
mainfrom
shell-exec-command

Conversation

@shykes

@shykes shykes commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Various improvements to dagger shell

dagger shell [-c COMMAND]

Execute a command in the shell and return (non-interactive). Great for agents. You can also pipe the command into stdin.

dagger shell go:dev -c 'go test ./...'
echo 'go test ./...' | dagger shell go:dev
cat f.txt | dagger shell -c 'cat -n'    # with -c, stdin goes to the command

Fixes #10489.

dagger shell [--copy]

Copy a directory into the container.

dagger shell --copy /src=. --copy /dagger=https://github.com/dagger/dagger

dagger shell [--init]

Run an init shell command in the container.

dagger shell --copy /src=. --init 'cd /src && go mod download'

Default shell

Without a pattern, open the only container, or else the only container in the entrypoint module.

dagger shell

Fixes #14281

API changes

input TerminalCopy {
  path: String!
  source: ID! @expectedType(name: "Directory")
}

extend type TerminalGroup {
  "Run the selected terminal's command, with args appended, without a terminal. Any exit code is allowed."
  exec(args: [String!] = [], stdin: String = "", copy: [TerminalCopy!] = [], init: [String!] = []): Container!
}

# New optional arguments on an existing field:
#   TerminalGroup.run: TerminalGroup!
#   TerminalGroup.run(copy: [TerminalCopy!] = [], init: [String!] = []): TerminalGroup!

TerminalGroup.run and exec now select the default target when the selection matches more than one target, instead of returning an error.

@shykes shykes changed the title shell: run an optional command non-interactively dagger shell improvements Sep 22, 2026
@shykes
shykes marked this pull request as ready for review September 22, 2026 21:54
@shykes
shykes requested review from a team as code owners September 22, 2026 21:54
'dagger shell NAME COMMAND [ARGS...]' runs COMMAND in the named shell,
prints its output, and exits with its exit code. Like the interactive
shell, each call runs the command again.

Add TerminalGroup.exec, which runs the command in the same container
that TerminalGroup.run opens.

Fixes #14282

Signed-off-by: Solomon Hykes <[email protected]>
'dagger shell NAME -c COMMAND' writes COMMAND to the standard input of
the shell's terminal command, instead of running it as exec arguments.
If stdin is not a terminal, 'dagger shell NAME' reads the command from
it. Positional arguments stay NAME only, and flags parse normally.

TerminalGroup.exec now takes stdin instead of args.

Signed-off-by: Solomon Hykes <[email protected]>
--copy [PATH=]SOURCE copies a directory into the shell's container.
SOURCE is resolved with Address: a local path, a Git URL, or another
address. PATH defaults to the working directory.

--init COMMAND writes COMMAND to the standard input of the shell's
terminal command before the shell opens. Only its changes to the
filesystem are kept. Init steps can be cached.

Both apply to the interactive shell and to -c. TerminalGroup.run and
TerminalGroup.exec get copy and init arguments.

Signed-off-by: Solomon Hykes <[email protected]>
If a terminal selection matches more than one target, select the only
container, or else the only container in the workspace entrypoint
module. So 'dagger shell' and 'dagger shell -c' work without a pattern.

Fixes #14281

Also simplify:
- Directory.Terminal and terminal targets share one container helper.
- Container.WithTerminalDefaults replaces two copies of the default
  terminal command logic.
- TerminalSetupArgs is used directly by the schema and core.
- terminalType replaces supportsTerminal and the type switches.
- Evaluate the terminal container once.
- Show the stdin message only when stderr is a terminal.
- Merge the non-interactive integration tests.

Signed-off-by: Solomon Hykes <[email protected]>
-c COMMAND now runs the terminal command with '-c COMMAND', as sh does,
so the command can read stdin: 'cat f | dagger shell -c "cat -n"'.
Without -c, a piped or redirected stdin is the script. Terminals and
other devices, such as /dev/null, are not read. Empty scripts fail.

TerminalGroup.exec takes args to append to the terminal command, and
stdin. Init steps also use -c.

Also:
- Mount /src read-write for directory shells, so --copy and --init
  can change it. Directory.terminal stays read-only.
- Add a 'dagger shell -l' hint when no default shell is found.
- Test the default selection, directory targets, stdin, and failed
  init steps.

Signed-off-by: Solomon Hykes <[email protected]>
@shykes
shykes merged commit 2a78967 into main Sep 22, 2026
86 checks passed
@shykes
shykes deleted the shell-exec-command branch September 22, 2026 23:12
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.

dagger shell: default shell 🐞 memory leak in dagger shell

2 participants