# exec

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

## Usage

```bash
bdy target exec [options] [command]
```

Run commands on a target and manage executions

## Options

| **Option** | **Description** |
| :--- | :--- |
| `--context <name>` | Connection and scope context: default, git, link or a saved name. Overrides the globally active context for this invocation. |
| `--examples` | Show only examples; with this flag --format accepts text, json or jsonl |
| `--verbose` | Show REST API requests, responses, timing and retries on stderr |
| `-h, --help` | display help for command |

## Available Commands

| **Command** | **Description** |
| :--- | :--- |
| [command](https://buddy.works/docs/cli/target/exec/command.md) | Execute a command on a target Required scopes: TARGET_USE |
| [kill](https://buddy.works/docs/cli/target/exec/kill.md) | Cancel a running execution Required scopes: TARGET_USE |
| [list](https://buddy.works/docs/cli/target/exec/list.md) | List target executions Required scopes: TARGET_READ |
| [logs](https://buddy.works/docs/cli/target/exec/logs.md) | Show execution logs Required scopes: TARGET_READ |
| [status](https://buddy.works/docs/cli/target/exec/status.md) | Show the status of an execution Required scopes: TARGET_READ |

Documentation for bdy v1.25.38

## Examples

### Return the execution state using semantic exit codes

```bash
bdy target exec command target-identifier "SELECT 1" --exit-code
```

### Run a command on a target and print its output

```bash
bdy tg exec command target-identifier "ls -la"
```

### Run SQL on a MySQL target

```bash
bdy tg exec command target-identifier "SELECT 1"
```

### Start a command in background and return the execution id

```bash
bdy tg exec command target-identifier "ls -la" --async
```

### Run a command from a file

```bash
bdy tg exec command target-identifier --file ./query.sql
```

### Print the result with execution metadata as JSON

```bash
bdy tg exec command target-identifier "SELECT 1" --format json
```

### Cancel running execution

```bash
bdy tg exec kill target-identifier exec-id
```

### Cancel running execution and automatically confirm

```bash
bdy tg exec kill target-identifier exec-id -f
```

### List executions of a target

```bash
bdy tg exec ls target-identifier
```

### List last 5 executions

```bash
bdy tg exec ls target-identifier --limit 5
```

### Return the execution state using semantic exit codes

```bash
bdy target exec logs target-identifier exec-id --exit-code
```

### Show logs of execution

```bash
bdy tg exec logs target-identifier exec-id
```

### Show logs of execution starting from line 100

```bash
bdy tg exec logs target-identifier exec-id --offset 100
```

### Return log records as JSONL

```bash
bdy target exec logs target-identifier execution-id --format jsonl
```

### Return the execution state using semantic exit codes

```bash
bdy target exec status target-identifier exec-id --exit-code
```

### Show status of execution

```bash
bdy tg exec status target-identifier exec-id
```


---
Original source: https://buddy.works/docs/cli/target/exec