# spin exec

**Spinbox is experimental: APIs change and data may be lost.** What is built and what proves it is on [Status](https://docs.spinbox.dev/reference/status.md); what Spinbox does not do is on [Limitations](https://docs.spinbox.dev/overview/limitations.md).

> spin exec: Run a command in a workspace.

<!-- Generated by tools/refgen from spin:cmd/cli. Edit the source, not this file. -->

```
Run a command inside a workspace and stream its output.

The command runs over the same brokered connection as 'spin ssh', so it needs no direct
network access to the workspace. Its standard input, output and error are connected to
yours, and its exit status becomes this command's exit status.

A terminal is allocated when both ends are one - so an interactive program works and a
pipeline does not get control characters in its data. Force either with --tty/--no-tty.

--detach starts the command under systemd in the workspace and prints its run id: it goes on
after this command ends, and its output and error, merged, are kept on the workspace's disk.
--attach <id> prints that output from the start and follows it until the run ends, with its
exit status. 'systemctl stop spin-exec-<id>' in the workspace stops it.

Examples:
  spin exec my-workspace -- ls -la
  spin exec my-workspace -- npm run build
  spin exec my-workspace --tty -- bash
  spin exec my-workspace -w /srv/app -- git status
  spin exec my-workspace -- cat build.log > local.log
  spin exec my-workspace --detach -w /srv/app -- make release
  spin exec my-workspace --attach 3f9a0c1d2e4b

Usage:
  spin exec <workspace> -- <command> [args...] [flags]

Flags:
      --attach string         Print a detached run's output until it ends, and exit with its status
  -d, --detach[=true|false]   Start the command, print its run id and leave it running
  -h, --help[=true|false]     help for exec
  -i, --identity string       Identity file (private key)
      --no-tty[=true|false]   Do not allocate a terminal
      --start[=true|false]    Start the workspace first if it is stopped
      --timeout duration      How long to wait for the workspace to be running; by default, until the control plane gives up on it
  -t, --tty[=true|false]      Allocate a terminal even if this one is not
  -u, --user string           User to run the command as (default "root")
  -w, --workdir string        Directory to run the command in

Global Flags:
      --config string        config file (default is $HOME/.spin/config.yaml)
  -o, --output string        text for a person, or json: one document of what the API answered, and no prose (default "text")
      --profile string       named profile to use; SPIN_PROFILE names it when this flag does not (default "default")
      --traceparent string   the W3C traceparent of the span this command is part of; its own span is sent to the installation unless the profile says telemetry: false
```
