Safetensors is a file format for storing the numbers inside a neural network. It was built to fix one specific problem: model files that can run code when you open them.
The problem it solves
For years the default way to save PyTorch model weights used Python's pickle format. Pickle is flexible, but it can contain instructions that execute during loading. Python's own documentation warns that malicious pickle data can run arbitrary code when it is unpickled, and says never to unpickle data from an untrusted source. Downloading a model from a stranger and loading it was, in effect, running a stranger's program. That is a textbook supply chain attack route and a path to remote code execution.
How it works
A safetensors file has a simple layout: a small JSON header that describes each tensor (its name, shape and where its bytes start), followed by the raw bytes of the tensors. There are no instructions in it, only data. A loader reads the header, then reads the byte ranges it points to. Nothing in the file can be "run."
The format was designed with Hugging Face, EleutherAI and Stability AI and has been through an outside security audit. As a bonus it is fast: files can be mapped into memory and loaded lazily, which helps with very large models.
What it does not cover
Safetensors protects the weights file, not everything around it. A model repository can still include other files: configuration, custom Python code that a library will execute if you allow it, and text such as a chat template. Those can carry their own risks. Safetensors also stores only tensors, so it cannot hold the tokenizer or a template by itself. Other formats, such as GGUF, bundle more into one file and so need their own care.
Why it matters to you
If you download open models, prefer safetensors files over pickle-based ones such as old .bin or .pt checkpoints. It is the cheapest safety upgrade available, and most major open models now publish in it. It does not make a model trustworthy. It only removes one way a file can attack you during loading.
Safetensors is a storage format for a model checkpoint. Downloading and running open-weight models yourself is where it matters most, and it pairs with habits like dependency pinning: know exactly which files you are running.