Part III — Advanced Systems · Chapter 14 · Lesson 1 of 5 · 4 min read
Lesson 1: Capability-Safe Execution and Least Privilege
Lesson level: Advanced
Purpose: Understand the runtime security model in depth: what a capability is, how the host grants and scopes it, how denial works, and how to design scripts and hosts around least privilege.
Release note: capability names, policy formats, and host APIs in this lesson are illustrative. Verify them against your installed v0.63 release.
Learning objectives
By the end of this lesson, you should be able to:
- Define a capability and contrast it with ambient authority.
- Describe how hosts grant, scope, and deny capabilities.
- Design a minimal capability set for a script.
- Explain how capabilities combine with package permissions and async host calls.
- Diagnose permission errors without weakening policy.
1.1 Ambient authority versus capabilities
In many languages, any code can open any file or connect to any host the process can reach. That is ambient authority: power comes from simply running. PeaLang instead treats sensitive operations as capabilities: a script can perform them only if the host has explicitly granted them, and only within the granted scope.
1.2 The capability families
| Family | Examples of scope |
|---|---|
| File read | Specific directories or files |
| File write | Specific output directories |
| HTTP | Allowed hosts, methods, and paths |
| Process | Usually denied; specific executables if ever granted |
| Logging | Structured logging allowed or denied |
| Concurrency | Whether tasks may be started, and how many |
| Host functions | Each registered function names the capability it needs |
Chapter 8 introduced these from the script's side. This lesson takes the host's view.
1.3 Deny by default
A runtime with no explicit grants should be able to compute, branch, loop, and return values, but not touch the file system, network, or processes. Every grant is an addition that must be justified.
1.4 Granting capabilities
# host policy (illustrative)
[capabilities]
file_read = ["data/policies/"]
file_write = []
http = [{ host = "rates.example.com", methods = ["GET"] }]
process = false
logging = true
tasks = { max = 10 }
Each entry is narrow: one directory, one host, one method. Wildcards such as "any host" or the root directory defeat the purpose.
1.5 Scoping by path and host
Path scopes are checked after resolving relative segments and links, so data/policies/../../secrets is outside data/policies/. HTTP scopes check the final host after redirects. Hosts should normalize before checking, not after.
1.6 Narrow host functions instead of broad capabilities
Often the safest grant is no raw capability at all. Instead of granting HTTP access to an exchange-rate service, the host exposes host.rate_for(currency), which validates the currency code, calls the service, and returns a number. The script gets the answer without the ability to call arbitrary URLs.
1.7 How the layers combine
| Layer | Decides |
|---|---|
| Package permission manifest (Chapter 11) | What a dependency asks for |
| Project policy | What the project allows any dependency |
| Host runtime grants | What this execution may actually do |
| Host function design | How narrow each operation is |
An operation succeeds only if every layer allows it. A package that declares HTTP access still fails at runtime if the host did not grant it.
1.8 Denial and permission errors
A denied operation raises a permission error naming the capability, not the secret details of the resource. Scripts should not catch and ignore permission errors; they indicate a design or policy mismatch the host must see.
1.9 Designing a minimal set
- List what the script must read, write, call, and log.
- Replace raw access with narrow host functions where possible.
- Grant the remaining capabilities with the smallest scopes.
- Run tests with exactly that set and confirm nothing else is needed.
- Record the set and the reason for each entry.
1.10 Worked example
The order_rules service needs customer tiers, stock checks, and a policy file. The final design grants no raw HTTP or database access. It exposes host.lookup_tier and host.reserve_stock under named capabilities, grants file read only to data/policies/, allows structured logging, and denies process execution. A test confirms that an attempt to read data/secrets.json raises a permission error.
1.11 Common mistakes
| Mistake | Consequence | Fix |
|---|---|---|
| Granting broad access during development | Broad access ships to production | Start from deny and add narrowly |
| Checking paths before normalizing | Traversal escapes the scope | Normalize, then check |
| Catching permission errors in scripts | Hidden policy problems | Let them reach the host |
| Raw HTTP where a host function would do | Larger attack surface | Expose narrow host functions |
1.12 Guided practice
- Write a minimal policy for a script that reads one CSV and writes one report.
- Replace a raw HTTP grant with a narrow host function design.
- Predict whether a given path is inside a granted scope after normalization.
- Trace which layer blocks a package that requests process access.
1.13 Hands-on lab
Run the order_rules service under a deny-by-default policy. Add grants one at a time until tests pass, recording each. Then add negative tests for file traversal, an unlisted HTTP host, and process execution.
Deliverable: the final policy with reasons, and test output for each negative case.
1.14 Review questions
- What is ambient authority?
- Why is deny-by-default safer?
- Why are narrow host functions often better than raw capabilities?
- How do package permissions and runtime grants interact?
- Why should scripts not swallow permission errors?
1.15 Applied challenge
Audit a script from an earlier chapter. List every capability it uses, propose a narrower design for each, and estimate how the attack surface changes.
Lesson summary
- Capabilities replace ambient authority with explicit grants.
- Grants are narrow, normalized, and justified.
- Narrow host functions often remove the need for raw access.
- Every layer must allow an operation for it to succeed.
Transition to Lesson 2
Capabilities decide what a script may do. Lesson 2 decides how much: time, instruction, memory, recursion, stack, collection, output, HTTP, and file-read limits.
Lesson status: Ready for review.