Skip to content

Starlark Code Mode and Built-In Read-Only Tools

Standard LLM tool loops waste turns and tokens fetching one resource at a time and stuffing full JSON payloads into conversation history. Faber’s Starlark Code Mode lets the model run one small, hermetic Starlark script (run_script) that calls multiple read-only tools in parallel, filters the results in memory, and returns only the distilled facts.

This guide covers Starlark Code Mode and Faber’s built-in read-only OCI registry inspection tools.

Code Mode embeds a hermetic go.starlark.net interpreter inside the agent runner (internal/engine/codemode):

  • Hermetic by construction: load() is disabled, and scripts have zero filesystem, shell, or raw network access. Scripts can only call the authorized read-only tools bound into the runner.
  • Hard-denied mutations: Sandbox tools (sandbox_*), submit_result, run_script, and mutating Kubernetes or write tools are unconditionally excluded from Starlark bindings.
  • Strict per-script budgets: Every invocation is bounded by bytecode step count (maxSteps, default 100000), wall-clock timeout (timeout, default 15s), nested tool calls (maxToolCalls, default 25), serialized result() size (maxOutputBytes, default 32768), and batch() worker concurrency (maxBatchConcurrency, default 4, clamped at 8).
  • Compact prompt surface: When hideWrappedTools is enabled (the default), individual wrapped read-only tools are collapsed behind run_script to save prompt tokens while run_script, submit_result, and any sandbox tools stay directly callable.

Inside run_script, Faber exposes wrapped read-only tools under clean namespaces:

  • k8s: k8s.list, k8s.get, k8s.logs, k8s.events
  • mcp.<server>: mcp.<server>.<tool> for each configured Streamable HTTP MCP Connector
  • oci: oci.list_tags, oci.resolve_digest for configured OCI registry Connector endpoints
  • tools: tools.<name> for any other bound read-only tools

Three built-in helpers keep scripts short and fast:

  • help() or help(k8s.list): Returns compact parameter signatures and descriptions for bound tools so the model can discover exact argument names without bloating the system prompt.
  • batch([call(fn, key="val"), call(other_fn, key="val")]): Runs multiple read-only tool calls concurrently in a bounded Go worker pool and returns their results in the same order.
  • result(value): Sets the compact JSON value returned to the LLM turn (every script must call result(value)).

Example Starlark script executed by the model in a single turn:

pods = k8s.list(resource="pods", namespace="apps")
unready = [p["name"] for p in pods["items"] if not p["ready"]]
logs, tags = batch([
call(k8s.logs, namespace="apps", name=unready[0]),
call(oci.list_tags, repository="ghcr.io/my-org/checkout", semverOnly=True, maxTags=5),
])
errors = [line for line in logs.splitlines() if "ERROR" in line]
result({
"pod": unready[0],
"errorCount": len(errors),
"latestTag": tags["tags"][0] if tags["tags"] else "",
})

For parameter names that match a Starlark keyword (such as from or in), scripts can pass a single positional dict argument instead of keyword arguments, for example mcp.prom.query({"from": "5m"}).

Built-In Read-Only OCI Registry Inspection (Connector type: oci)

Section titled “Built-In Read-Only OCI Registry Inspection (Connector type: oci)”

Declare one or more Connector resources with spec.type: oci to expose two operator-side, SSRF-guarded Distribution Spec v2 tools without pulling image layers or blobs:

  • oci_list_tags (oci.list_tags in Code Mode): Lists repository tags with optional prefix, semverOnly sorting, and maxTags (default 50, hard cap 200).
  • oci_resolve_digest (oci.resolve_digest in Code Mode): Resolves a tag or reference via HEAD and GET manifest lookup and returns content digest, media type, and multi-arch platform metadata.
apiVersion: faberops.dev/v1beta1
kind: Connector
metadata:
name: ghcr-readonly
namespace: faber
spec:
type: oci
url: https://ghcr.io
capabilities:
- read
secretRef:
name: ghcr-pull-credentials
key: .dockerconfigjson

Guardrails:

  • Each Connector spec.url host is added to an exact registry allowlist (for example ghcr.io or registry.k8s.io). Empty allowlists fail closed and wildcards (*, *.example.com) are rejected.
  • Optional secretRef supplies pull credentials from a same-namespace Secret (supporting .dockerconfigjson, username:password, or a bearer token).
  • Environment HTTP proxies are ignored and private, loopback, and link-local IP ranges are blocked at dial time.

See config/samples/connector-observability.yaml and the CRD API Reference for configuring Connector resources.

Faber’s offline eval suite includes a multi-tool Starlark Code Mode fixture (codemode-multi-tool) verified through the real engine and governors:

Terminal window
make eval