> For the complete documentation index, see [llms.txt](https://chaincontext.gitbook.io/help-center/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chaincontext.gitbook.io/help-center/safety/pre-execution-simulation.md).

# Pre-execution Simulation

Every write-tool call is simulated via **Tenderly** and scanned by **Blockaid** before the unsigned tx is returned to the agent.

## What each provider does

* **Tenderly**: simulates the tx against a forked state. Returns success/failure, gas used, asset changes (`"will transfer 100 USDC from you to 0xabc"`), decoded call trace, and a simulation URL to share.
* **Blockaid**: scans for malicious patterns. Returns a risk score (0-100), validation result (Benign / Info / Warning / Malicious), and human-readable warnings.

## Configuration

### Plan defaults

| Plan       | Provider                            |
| ---------- | ----------------------------------- |
| Builder    | Tenderly only (platform-shared key) |
| Studio     | Both (platform-shared keys)         |
| Enterprise | Both (configurable, own-key option) |

### Per-tool

In the tool editor's **Security** panel:

* `preSimMode`: `off` · `warn` · `block`
* `warnThreshold`: Blockaid score that triggers user confirmation via elicitation (default 40)
* `blockThreshold`: Blockaid score that hard-blocks the tx (default 70)

### Bring your own keys (Studio+)

Paste your Tenderly + Blockaid API keys in project settings → **Third-Party API Keys**. They're stored encrypted in `project_secrets`. This gives you unlimited quotas + dashboard access under your own accounts.

## Flow

```
build_unsigned_tx produces tx
  → [Tenderly simulate]  → success, gas, decoded trace
  → [Blockaid scan_tx]   → riskScore, warnings
  → if riskScore >= blockThreshold → throw (hard block)
  → if riskScore >= warnThreshold AND elicit available → confirm dialog
  → return unsigned tx with _tenderly + _blockaid metadata
```

When HITL is also enabled, simulation results are displayed in the approval dashboard.

## References

* [Tenderly Simulation API](https://docs.tenderly.co/simulations-and-forks/simulation-api)
* [Blockaid Transaction Security](https://docs.blockaid.io/reference/evm-transaction-scan)
