> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fly.io/llms.txt
> Use this file to discover all available pages before exploring further.

# fly sprites exec

Run a command in a sprite and exit with its exit status.

Everything after the command name is passed to the command, so flags for
'fly sprites exec' itself must come before it. Use -- to make the split
explicit.

Without --tty the command's output is streamed and stdin is forwarded only
when it is piped or --stdin is passed. With --tty a pseudo-terminal is
allocated; press Ctrl+\ to detach and leave the command running, then use
'fly sprites attach' to reconnect.

Ports the command opens are forwarded to the same port on localhost while it
runs, unless --no-port-forward is passed.

## Usage

```
fly sprites exec [flags] -- <command> [args...]
```

## Examples

```
  fly sprites exec -- ls -la
  fly sprites exec --dir /app --env KEY=value,FOO=bar -- env
  printf 'hello' | fly sprites exec --stdin -- cat
  fly sprites exec --tty -- /bin/bash
  fly sprites exec -o my-org -s my-sprite -- npm start
```

## Options

```
      --dir string         Working directory for the command
  -e, --env stringArray    Environment variables as KEY=value. Repeat the flag, or give it once with comma-separated pairs
      --file stringArray   Upload a local file before running, as source:dest (can be repeated)
  -h, --help               help for exec
      --no-port-forward    Do not forward ports opened by the command to localhost
      --no-stdin           Do not read or forward stdin (without --tty)
  -o, --org string         The target Fly.io organization
  -s, --sprite string      The target sprite. Defaults to the one set with 'fly sprites use'
      --stdin              Read and forward stdin (without --tty)
      --tty                Allocate a pseudo-terminal
```

## Global Options

```
  -t, --access-token string   Fly.io API token to use, overriding FLY_ACCESS_TOKEN, FLY_API_TOKEN and the saved login
      --debug                 Print additional logs and traces
      --verbose               Verbose output
```

## See Also

* [fly sprites](https://docs.fly.io/flyctl/cmd/fly_sprites)	 - Manage Sprites: persistent Linux environments for development and agents
