2.5.2 Strategies & Mnemonics
Execution strategy and mnemonic answer two different questions about the same action. A strategy says where and under what runtime constraints Bazel executes the action. A mnemonic is the short action-type name Bazel uses to classify that action and route it. If you keep those roles separate, flags like --spawn_strategy=sandboxed and --strategy=Javac=worker stop looking arbitrary: the first picks a default execution environment, the second overrides that default for one class of actions.1,2,3
Try worker first. If Bazel cannot use it, fall back to local.
Strategy lists are tried from left to right.
The sandboxed strategy uses an OS-specific runner, such as linux-sandbox.
The strategy names worth recognizing first
At this level, the most useful strategy names are the ones you will configure directly or see as concrete local backends. local runs a command as a normal subprocess in the execroot. Older docs may still call this standalone. sandboxed keeps the action local but runs it in a restricted per-action directory, which connects directly back to 2.3.2 Sandboxing. worker routes actions through a long-lived tool process, remote sends them to a remote executor, and, when dynamic execution is enabled, dynamic starts local and remote branches together so the first branch to finish determines the outcome.1,4,5,6
sandboxed is also a reminder that one user-facing strategy name can hide a more specific implementation. When Bazel uses local sandboxing, the concrete backend may be linux-sandbox, darwin-sandbox, or processwrapper-sandbox, depending on platform support and fallback behavior.4 That is why logs and flags sometimes show both "sandboxed" and a backend-specific name: they are not different concepts so much as different levels of detail about the same execution choice.
Mnemonics name the action kind
A mnemonic is Bazel's short label for what an action does, such as Javac, CppCompile, Genrule, or AndroidManifestMerger.2 The important part is not memorizing every mnemonic. The important part is recognizing that mnemonics identify action categories. Android build performance, for example, is often tuned by configuring workers per mnemonic — names like DexBuilder, Javac, and Desugar — which makes it clear that the unit of control is the action type, not the top-level target you asked Bazel to build.7
That is why per-action routing uses the form --strategy=<mnemonic>=<strategy>. --spawn_strategy sets the default for ordinary actions, and --strategy overrides that default for one mnemonic at a time.1
bazel build //app:server \
--spawn_strategy=sandboxed \
--strategy=Javac=worker,local \
--strategy=Genrule=local
In that example, Bazel keeps sandboxing as the general local default, tries the worker strategy first for Javac actions with local as fallback, and forces Genrule actions to run locally without sandboxing.1,5 This is the basic routing model that later grows into the tuning work in 6.4 Execution Modes and Persistent Workers and the remote-cluster model in 6.3 Remote Execution Infrastructure.
Read the pair together
When you read an execution setting, ask two questions: "what action kind is this?" and "where will Bazel run it?" Javac=worker means Java compilation through a persistent compiler process. CppCompile=remote means C++ compilation sent to a remote executor. Temporarily changing --spawn_strategy=local while debugging does not create new actions or change their mnemonics. It only changes the execution environment for actions that would otherwise run under a different strategy.1,4,5 Persistent team defaults for these choices belong in 3.2 Project Configuration, not in BUILD files.
Use the genrule-sandbox-paths snippet to compare the correctly declared action with the same path mistake under different spawn strategies.
Strategy and mnemonic are two axes of the same action. Mnemonic names the work (Javac, Genrule, CppCompile). Strategy names the execution mode (worker, sandboxed, remote, dynamic, local). Most execution tuning is just matching those two axes more deliberately.
Check your understanding · 3 questions
1.Match each strategy name to its execution mode:
Drag each answer onto the matching prompt, or click an answer and then click a prompt
2.What does a mnemonic represent, and why does it matter for per-action strategy routing?
Select one answer
3.True or false: using strategy and mnemonic flags.
Choose True or False for each sentence
--spawn_strategy=sandboxed --strategy=Javac=worker,local sets sandboxing as the default for all actions but uses a persistent worker (with local fallback) for Java compilation specifically.--spawn_strategy=local for debugging creates new actions with different inputs and outputs than the sandboxed version.Footnotes
-
Command-Line Reference —
--spawn_strategy,--strategy=<mnemonic>=<strategy>,--strategy_regexp, and thelocal/standalonenaming ↩1 ↩2 ↩3 ↩4 ↩5 -
Bazel Glossary — mnemonic definition, example mnemonics, and spawn strategies in the execution phase ↩1 ↩2
-
What are Bazel's strategies? — the mental split between strategy choice and action identity ↩
-
Sandboxing —
sandboxedversuslocal, pluslinux-sandbox,darwin-sandbox, andprocesswrapper-sandbox↩1 ↩2 ↩3 -
Persistent Workers —
workerstrategy,--strategy=Javac=worker,local, and worker fallback vocabulary ↩1 ↩2 ↩3 -
Dynamic Execution — enabling the
dynamicstrategy and how the first-finishing branch determines the result ↩ -
Android Build Performance — concrete worker-capable mnemonics such as
DexBuilder,Javac, andDesugar↩