Skip to content

Add --container and --no-container to fly machine exec - #5077

Open
dangra wants to merge 1 commit into
masterfrom
pilot-machine-namespace-exec
Open

Add --container and --no-container to fly machine exec#5077
dangra wants to merge 1 commit into
masterfrom
pilot-machine-namespace-exec

Conversation

@dangra

@dangra dangra commented Aug 13, 2026

Copy link
Copy Markdown
Member

fly machine exec has never had a way to choose where a command runs. It sets no container on the request, so on a machine with containers it lands in whichever one the platform picks first, and there is no way to reach the machine itself.

This adds both halves of that choice:

fly machine exec --container app "ps aux"
fly machine exec --no-container "ps aux"

--container names one. --no-container asks for the machine's own namespace instead — the same flag, meaning the same thing, as on fly ssh console (#5075). Passing both is an error.

Behaviour

  • Without either flag nothing changes.
  • Against a machine running an older platform version, --no-container is ignored and the command runs in a container as it does today. That is the one silent case in this change: the request field is simply unknown to the older API, so it cannot report the mismatch. The platform-side support needs to have rolled out before this is relied on.

Depends on superfly/fly-go#276 for the machine request field; CI here fails on unknown field Machine in struct literal of type fly.MachineExecRequest until that lands and the go.mod bump follows.

`fly machine exec` had no way to choose where a command runs: it never
set a container, so it landed in whatever the platform picked first.

--container names one. --no-container asks for the machine's own
namespace instead, matching the flag `fly ssh console` uses for the same
choice. Passing both is an error.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit targeting for where fly machine exec runs a command by introducing --container (run inside a named container) and --no-container (run in the machine’s own namespace), with a mutual-exclusion check.

Changes:

  • Add --container and --no-container flags to fly machine exec.
  • Validate the flags are mutually exclusive.
  • Populate the exec request with Container / Machine selection fields.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 93 to +97
in := &fly.MachineExecRequest{
Cmd: command,
Timeout: timeout,
Cmd: command,
Container: container,
Machine: noContainer,
Timeout: timeout,
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