> ## Documentation Index
> Fetch the complete documentation index at: https://bruno-a6972042-mintlify-c74cb75a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Script Flow in Bruno

In Bruno, we provide two types of script flows: **Sandwich** and **Sequential**. These flows control the order in which pre-request scripts, post-response scripts, and test scripts at various levels of your API test collections are executed, allowing for flexibility and control over your automation.

## Flow Types

1. Sandwich Flow
2. Sequential Flow

### 1. Sandwich Flow

In the **Sandwich Flow**, scripts are executed in the following order:

```bash theme={null}
sandwich-flow/
├── Collection Pre Script
│   └── Folder Pre Script
│       └── Request Pre Script
├── Request Post Script
│   └── Folder Post Script
│       └── Collection Post Script
└── Request Test Script
    └── Folder Test Script
        └── Collection Test Script
```

**Execution order:**

1. Collection Pre Script
2. Folder Pre Script
3. Request Pre Script
4. Request Post Script
5. Folder Post Script
6. Collection Post Script
7. Request Test Script
8. Folder Test Script
9. Collection Test Script

This order nests pre-scripts inward and post-scripts / test scripts outward. It is useful when you need to set up state at broader scopes first, then tear down or assert from the request level back out to the collection.

### 2. Sequential (Natural) Flow

In the **Sequential Flow**, scripts are executed in this order:

```bash theme={null}
sequential-flow/
├── Collection Pre Script
│   └── Folder Pre Script
│       └── Request Pre Script
├── Collection Post Script
│   └── Folder Post Script
│       └── Request Post Script
└── Collection Test Script
    └── Folder Test Script
        └── Request Test Script
```

**Execution order:**

1. Collection Pre Script
2. Folder Pre Script
3. Request Pre Script
4. Collection Post Script
5. Folder Post Script
6. Request Post Script
7. Collection Test Script
8. Folder Test Script
9. Request Test Script

This flow runs each phase (pre, post, test) from collection → folder → request. It may be better suited when you want a clean top-to-bottom execution at every stage.

## Setting the Flow Type

<Note>
  If the `flow` property is not specified, Sandwich is used by default.
</Note>

You can set the flow type (either `sandwich` or `sequential`) in your collection configuration file:

<Tabs>
  <Tab title="YAML Collections">
    ```yaml title="opencollection.yml" theme={null}
    extensions:
      bruno:
        scripts:
          flow: sequential  # Or "sandwich"
    ```
  </Tab>

  <Tab title="Bru Collections">
    ```json title="bruno.json" theme={null}
    {
      "scripts": {
        "moduleWhitelist": ["crypto", "buffer", "form-data"],
        "filesystemAccess": {
          "allow": true
        },
        "flow": "sequential"
      }
    }
    ```
  </Tab>
</Tabs>

## Resources

* [Blog - Script Flow in Bruno](https://blog.usebruno.com/script-flow-in-bruno)
