Per the Swift expression macros proposal, macro implementations are intended to run in a sandbox, like SwiftPM plugins, which prevents file system and network access. A macro should depend on the syntax it is given and nothing else. That reduces risk but does not remove the need to review macro packages you add.
What a macro is
A macro is a separate program that works on Swift syntax trees through the swift-syntax package. The externalMacro built in invokes that program and hands it the source code of the macro expansion. The result is more Swift code, inserted at the use site and compiled with your app.
What the proposal says about security
| Point | Detail |
|---|---|
| Sandbox | Implementations are executed in a sandbox like SwiftPM plugins |
| Blocked | File system and network access |
| Input | The expansion node, its child nodes, and what the expansion context provides |
| Recursion | Macro expansion cannot be recursive |
The stated reasons are security and encouraging macros to depend on their input alone. The proposal leaves the details of how implementation modules are built and provided to the compiler to a separate proposal, and it does not specify how the sandbox is enforced on each platform.
What a sandbox does not cover
The sandbox restricts what the macro can do while it runs. It does not constrain what code the macro writes. A macro could expand into code that reads files or calls a server when your app runs. The sandbox protects the build machine, not your users.
A review routine for macro packages
- Treat a macro package like any other dependency. Add it to your inventory with a version.
- Expand the macros in a scratch project and read the generated code.
- Check what the generated code does at runtime: network calls, storage, reflection.
- Pin the version, and review again on updates.
- Prefer macros whose generated code is small and readable.
- Check the maintainer and the repository URL before adding.
See also how to list every dependency in an iOS app for keeping that inventory.
Try it yourself
Click through it at your own pace, or open it full screen. Notice how every package is listed with its version, which is where a macro package belongs.
Safeguard builds an SBOM and scans your dependencies for known vulnerabilities, and you can run a free scan at gold.safeguard.sh/scan to see what your own project pulls in.
Quick check
Can a macro read my files during compilation?
The proposal says the sandbox prevents file system and network access for macro implementations.
Can macro generated code still be harmful?
Yes. Generated code is compiled into your app and runs with your app's permissions, so read it.
Sources
Last reviewed: 19 October 2026.