# Safetensors

> Canonical: https://skillalmanac.com/glossary/safetensors | Last verified: 2026-11-24 | Index status: not offered to search engines

Safetensors is a file format for storing tensors, the arrays of numbers that make up a model's weights. Its documentation describes it as a simple format for storing tensors safely, as opposed to pickle, while still being fast.

Also called: safetensor, safetensors format, .safetensors, safetensors file.

## In plain language

A trained AI model is, in the end, a very large set of numbers saved in files. Safetensors is one way of saving those numbers. Its main selling point is safety: older Python model files used a format called pickle, which can run code when you open it, so opening a file from a stranger was a risk. A safetensors file holds only numbers and a small description of them, so opening it does not run anything. Think of a sealed parcel of data versus a parcel that might contain a program. It does not tell you whether a model is good, honest or licensed for your use, and it does not protect you from other risks such as a malicious script that downloads or loads the file.

## Technical definition

A safetensors file starts with 8 bytes holding an unsigned little-endian 64-bit integer N, the size of the header. The next N bytes are a JSON header that gives each tensor's dtype, shape and data offsets. The rest is one byte buffer of tensor data, which the README says must be fully indexed with no holes. Because the header says where every tensor sits, a reader can load only some tensors, and the documentation describes loading without copying (zero-copy). The README says pickle is unsafe because it runs arbitrary code, and it mentions a header size limit as protection against denial-of-service files.

## How it shows up when you use agents

You meet safetensors as a file extension. When you download an open-weight model, the folder often contains one or more `.safetensors` files next to a configuration file. Libraries such as the [Transformers library](/glossary/transformers-library) and tools built on [PyTorch](/glossary/pytorch) read them, and the format's documentation lists several projects that use it. Other formats exist for other runtimes, for example [GGUF](/glossary/gguf).

What breaks when this is misunderstood: people take "safe" to mean the whole download is safe. The format removes one risk, code running when a weights file is opened. It does not vet the model's behaviour, its licence or the loading script around it. Another mistake is expecting every runtime to accept the file. A runtime that expects a different format needs a converted copy.

Next action: before downloading, check the model page for the file format, who published it and the licence, and use a sizing check so the [model weights](/glossary/model-weights) fit in your memory. If a coding agent writes the loading code, read that code before running it.

## Common confusions

- **Safetensors versus pickle.** Pickle can run code on load, according to the project's README. Safetensors stores numbers and a JSON header only.
- **Safetensors versus a model.** It is a container for tensors. The architecture, tokenizer and licence come from other files and pages.
- **Safetensors versus GGUF.** Both store model data, for different tools. Check which format your runtime expects.
- **Myth.** A safetensors file guarantees a trustworthy model. It addresses how the file is read, not what the model does.

## Worked examples in this catalogue

### [local-model-sizing](https://skillalmanac.com/skills/skill-almanac/local-model-sizing)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A script that works out whether an open-weight language model will run on a given GPU, Mac or PC, computing weight, KV-cache and overhead memory per quantization level.

Why it exercises the concept: The weights it sizes are the numbers a file such as a .safetensors file stores. Sizing first tells you whether a download is worth fetching.

### [Self-Hosting an AI Agent: What You Take On](https://skillalmanac.com/learn/self-hosted-ai-agent-considerations)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A checklist for running an agent on your own machine, including the model server that holds the weights and a note to work out memory needs before you download a large model.

Why it exercises the concept: Self-hosting means obtaining weight files and loading them. The guide covers fit and exposure; it does not cover file formats, so treat it as context for where the format matters.

### [skill-safety-audit](https://skillalmanac.com/skills/skill-almanac/skill-safety-audit)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Scans a third-party agent skill folder and returns a JSON risk table with evidence lines before you install it.

Why it exercises the concept: Safetensors exists so that opening a model file does not run code. This skill applies the same check-before-you-run habit to skill folders. It does not inspect model files.

## Related terms

- [Model weights](https://skillalmanac.com/glossary/model-weights.md)
- [PyTorch](https://skillalmanac.com/glossary/pytorch.md)
- [Hugging Face](https://skillalmanac.com/glossary/hugging-face.md)
- [GGUF](https://skillalmanac.com/glossary/gguf.md)
- [AI model](https://skillalmanac.com/glossary/ai-model.md)
- [Open-weights model](https://skillalmanac.com/glossary/open-weights-model.md)

## Sources

- [Safetensors documentation](https://huggingface.co/docs/safetensors/index), Hugging Face (accessed 2026-11-24)
- [safetensors README](https://github.com/safetensors/safetensors), GitHub (safetensors project) (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
