---
title: "Put code samples under a licence that lets · Agent Wranglers"
url: https://agentwranglers.se/playbook/documentation/examples-that-run/sample-code-licence
id: DOC-38
level: Recommended
updated: 2026-10-22
build: a2a6bdfed830
tokens: 921
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Put code samples under a licence that lets readers copy them

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Examples that run](https://agentwranglers.se/playbook/documentation/examples-that-run.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: DOC-38
- Level: Recommended
- Chapter: [Examples that run](https://agentwranglers.se/playbook/documentation/examples-that-run.md)
- Rule: State the licence of the code samples in the docs apart from the licence of the prose. Pick one that asks nothing back, such as 0BSD or MIT-0, so readers can paste samples into closed code.
- Check: The docs footer names the samples' SPDX licence identifier. A licence check of the docs repository, such as `reuse lint`, finds a licence for every sample file.
- How: Readers who cannot tell whether they may copy a sample either retype it or copy it without the right. A licence written for prose, such as CC BY, asks for credit on every copy and fits text better than code. 0BSD grants permission "to use, copy, modify, and/or distribute this software for any purpose". Name the licence in the docs footer and the docs repository. Use SPDX identifiers, as [Mark every file with its licence and copyright holder](https://agentwranglers.se/playbook/open-source/licences-and-copyright/spdx-file-headers.md) says. Samples taken from another project keep their own licence, as [Keep copied code under its own licence](https://agentwranglers.se/playbook/open-source/licences-and-copyright/third-party-notices.md) says. Keep samples runnable, as [Make every example complete enough to copy and run](https://agentwranglers.se/playbook/documentation/examples-that-run/complete-examples.md) asks.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### TOML example

```toml
# REUSE.toml: samples under 0BSD, prose under CC-BY-4.0
version = 1

[[annotations]]
path = "docs/examples/**"
SPDX-FileCopyrightText = "2026 Example Bakery AB"
SPDX-License-Identifier = "0BSD"

[[annotations]]
path = "docs/**/*.md"
SPDX-FileCopyrightText = "2026 Example Bakery AB"
SPDX-License-Identifier = "CC-BY-4.0"
```

## Sources

- [Open Source Initiative: Zero-Clause BSD](https://opensource.org/license/0bsd)
- [REUSE](https://reuse.software/)

## Related rules

- OSS-3 [Mark every file with its licence and copyright holder](https://agentwranglers.se/playbook/open-source/licences-and-copyright/spdx-file-headers.md) in Open source maintenance
- OSS-5 [Keep copied code under its own licence](https://agentwranglers.se/playbook/open-source/licences-and-copyright/third-party-notices.md) in Open source maintenance
- DOC-21 [Make every example complete enough to copy and run](https://agentwranglers.se/playbook/documentation/examples-that-run/complete-examples.md) in Documentation

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/documentation/examples-that-run/sample-code-licence">Agent Wranglers documentation playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Show each API example in every language you ship an SDK for](https://agentwranglers.se/playbook/documentation/examples-that-run/examples-per-sdk.md)
- [Examples that run](https://agentwranglers.se/playbook/documentation/examples-that-run.md)
