ScriptsJul 18, 2026·3 min read

Starlark — Configuration Language for Build Systems

A deterministic dialect of Python designed for configuration and build system definitions, used by Bazel, Buck2, and other build tools.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Starlark Config Language
Direct install command
npx -y tokrepo@latest install 3ff0e9fb-82e9-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

Starlark (formerly known as Skylark) is a configuration language designed by Google for use in build systems. It is a strict subset of Python with intentional restrictions — no classes, no exceptions, no mutation after freezing — that guarantee deterministic, hermetic evaluation suitable for parallel and cached builds.

What Starlark Does

  • Defines build targets, rules, and dependencies in a Python-like syntax
  • Guarantees deterministic evaluation for reproducible builds
  • Provides sandboxed execution with no file I/O or network access
  • Enables macro and rule authoring for custom build logic
  • Powers configuration in Bazel, Buck2, Pants, and other build systems

Architecture Overview

Starlark is an interpreted language with a two-phase execution model: a loading phase that evaluates BUILD files and produces a dependency graph, and an analysis phase that resolves configurations. The language is frozen after loading — all values become immutable — preventing non-determinism. Implementations exist in Go (go.starlark.net), Java (within Bazel), and Rust.

Self-Hosting & Configuration

  • Used automatically when writing BUILD or .bzl files for Bazel
  • Go implementation available: go get go.starlark.net/starlark
  • Rust implementation: starlark-rust crate for embedding
  • REPL available via starlark command for interactive testing
  • Linting via Buildifier for Bazel-specific Starlark files

Key Features

  • Python-like syntax with near-zero learning curve for Python developers
  • Guaranteed termination — no while loops or recursion allowed
  • Hermetic execution with no side effects or I/O
  • First-class functions and comprehensions for expressive configs
  • Parallel-safe evaluation due to immutability after load phase

Comparison with Similar Tools

  • CUE — Stronger typing and validation; Starlark is more flexible and imperative
  • Jsonnet — Similar functional config language; Starlark has Python syntax
  • Nickel — Contract-based with gradual typing; newer and less ecosystem support
  • HCL (Terraform) — Domain-specific for infrastructure; Starlark is general-purpose for builds

FAQ

Q: Is Starlark the same as Python? A: No. It is a subset with no classes, exceptions, global state, or I/O. Most simple Python expressions work, but programs that depend on mutation or side effects do not.

Q: Can I use Starlark outside of Bazel? A: Yes. The Go and Rust implementations can be embedded in any application as a configuration or scripting language.

Q: Why does Starlark forbid while loops? A: To guarantee termination. All iteration uses for loops over finite sequences, ensuring every evaluation completes in bounded time.

Q: How do I debug Starlark code? A: Use the print() function for logging during evaluation, or use the interactive REPL. Bazel also provides --output=starlark for query debugging.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets