> For the complete documentation index, see [llms.txt](https://docs.sail.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sail.money/protocol/architecture/safe-module-enabler.md).

# SafeModuleEnabler

`SafeModuleEnabler` is a tiny, stateless helper whose only job is to enable the Sail kernel as a Safe **module** on a freshly created Safe, in the same transaction that creates it. License: MIT.

## Why it's needed

Safe's `enableModule(address)` is gated by an `authorized` modifier requiring `msg.sender == address(this)` — i.e. the Safe can only enable a module via a call from *itself*. For a brand-new Safe that has not yet executed any owner transaction, the **only** window to satisfy that is the `to` / `data` **delegatecall** hook inside `Safe.setup`.

The enabler exploits exactly that window:

```solidity
contract SafeModuleEnabler {
    function enable(address module) external {
        ISafeModuleEnable(address(this)).enableModule(module);
    }
}
```

When `Safe.setup` **delegatecalls** `enable(module)`, `address(this)` resolves to the **Safe itself**, so the inner `enableModule(module)` is a valid Safe → Safe call. The kernel becomes a module before the first owner transaction ever runs.

## Properties

* **Stateless and reentrancy-safe by construction** — it holds no storage.
* **Must be delegatecalled.** Called directly, the inner `enableModule` targets the enabler (which has no such function) and reverts — so it cannot be misused as a standalone call.
* **Deployed once per chain** at a chain-identical address, and referenced as the `to` target in the Safe initializer passed to `SailKernel.createAccount`.

## How the kernel uses it

`createAccount` validates that the `to` target embedded in the Safe initializer (`safeInitializer[68:100]`) is on governance's `trustedModuleSetup` allowlist — so only this audited enabler can be the setup delegatecall target. After deployment, `createAccount` checks `ISafe(account).isModuleEnabled(address(this))` and reverts with `ModuleNotEnabled` if the enabler did not run. This is the structural defense (Octane #1) against an attacker supplying a malicious setup delegatecall that overwrites the proxy's storage.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sail.money/protocol/architecture/safe-module-enabler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
