# first_writable

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/_paths/first_writable)

Return the first candidate directory that accepts a file.

Shared by the managed-bin and update-lock resolvers, which both walk a
preferred-then-fallback pair. Callers keep their own "fell back" warning,
because the consequence of falling back differs between them.

## Signature

```python
first_writable(
    candidates: Sequence[Path],
    *,
    mode: int = 511,
    what: str,
) -> Path | None
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `candidates` | `Sequence[Path]` | Yes | Directories to try, most preferred first. |
| `mode` | `int` | No | Permission bits for directories this call creates. (default: `511`) |
| `what` | `str` | Yes | Noun phrase naming the directory's purpose, used in the log. |

## Returns

`Path | None`

The first usable directory, or `None` when none of them is.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/4bfa52000ef65ac623d8ada0cb67f67cbdd663ea/libs/code/deepagents_code/_paths.py#L484)