Environment-based Agents

Course overview

Browser Agents, desktop-control Agents, and coding Agents appear to use different tools, but they share the same engineering problem: the model sees only a bounded projection of an external state that continues to evolve and may be irreversible. A reliable system must model them as a controlled observation–action runtime, not as “give the model a screenshot or files, then execute whatever it says.”

This course gives the three environments one core contract:

Reproducible initial state → versioned observation → structured action proposal
→ schema / policy / permission / approval / budget checks
→ sandbox adapter execution → receipt + new observation
→ checkpoint / trace → independent verifier checks final state and side effects

Fact boundary

Sources were obtained or rechecked on 2026-07-22. This course uses the original papers/projects for WebArena, OSWorld, and SWE-bench, Playwright official documentation, and OWASP/NIST engineering-governance materials to derive stable boundaries. It does not maintain model leaderboards or a specific product UI. Browsers, operating systems, repositories, and benchmark harnesses change; pin versions, images, permissions, and evaluation data again before applying this material to a real environment.

Where this course fits

Complete these first:

  • Agent Core: state, checkpoints, idempotency, termination, and human control.
  • Tool Calling: schemas, authorization, call IDs, errors, and retries.

Before touching untrusted pages, email, repositories, or privileged actions, at least read Threat Modeling, Prompt Injection and Indirect Injection, and Identity and Least Privilege. This is an early safety gate; it does not require completing the production-governance and incident-response sections of AI Safety first.

This course applies those invariants to interactive environments. Continue afterward with Evaluation Framework, Runtime Monitoring, and LLMOps to turn a one-off demonstration into repeatable trials and release gates.

Learning objectives

  • Analyze browser, desktop, and coding environments with one observation–action loop.
  • Distinguish hidden authoritative environment state, Agent observation, runtime state, and model context.
  • Design action contracts with versions, scope, preconditions, risk, idempotency keys, and acceptance evidence.
  • Clearly separate user goal, model plan, delegated authority, environment identity, approval, and adapter receipt. A plan, page text, or model self-report can never escalate permission.
  • Use semantic locators and actionability in a browser instead of treating coordinate clicks as the default interface.
  • Set sandbox, least-privilege, approval, rollback, or compensation boundaries for desktop and code execution.
  • Recover long tasks with checkpoints, receipts, and external facts without repeating side effects.
  • Evaluate environment Agents through initial state, final state, trajectory, side effects, cost, and latency together.
  • Keep auditable identity, policy, digest, and time evidence while minimizing, redacting, and access-controlling sensitive raw content.
OrderLessonCore questionCompletion evidence
1A Unified Environment-Interaction ContractHow should goals, identity, state, observations, actions, and authorization be layered?Can draw delegation, control, and evidence boundaries
2Browser Agents and ActionabilityWhen is a page element safe to operate?Locator + actionability + final-state verifier
3Desktop Agents and Machine StateHow can focus, dialogs, and cross-application side effects be controlled?VM initial state and typed-action design
4Coding Agents and Verifiable PatchesHow can “tests passed” become bounded completion evidence?Repository snapshot + patch + bidirectional tests
5Sandboxes, Permissions, Approvals, and RollbackWhich controls must live outside the model?Risk tiers and authorization matrix
6Long-running Task Checkpoints and Idempotent RecoveryHow can work continue safely after a crash?Checkpoint schema and crash-window table
7Environment Evaluation and Integrated ProjectHow can you prove task success without out-of-scope side effects?Evaluation card and 103 offline tests

Plan 12–16 hours: 60–90 minutes for each of the first six lessons and 4–6 hours for the integrated project.

A unified view of three environments

EnvironmentExample observationExample action contractAuthoritative stateCompletion evidence
BrowserURL, accessibility tree, DOM summary, screenshot, network resultNavigate, locator click/fill, downloadSession, tab, storage, site backendPage assertion + backend business state + receipt
DesktopScreen, accessibility tree, windows/focus, file metadataFocus, click, type, launch, file operationOS, application, file system, clipboardExecutable final-state check + side-effect inventory
CodingCommit, worktree, files, index, test outputRead/search/edit/test/buildRepository snapshot, dependencies, worktreeTarget tests + regression tests + diff/policy checks

Screenshots, DOM, terminal output, and issue text are observations. They are not automatically trusted instructions; neither does a model-proposed action automatically obtain permission.

Hands-on entry point

The course project uses only Python’s standard library and an in-memory sandbox. It never calls a real browser, desktop, shell, network, or model:

Set-Location ".\docs-EN\environmental-agents"
$env:PYTHONDONTWRITEBYTECODE = "1"
python -B .\examples\environment_runtime.py
python -B -W error .\examples\test_environment_runtime.py
python -B -O -W error .\examples\test_environment_runtime.py

The project includes strict fixture/action/checkpoint schemas; path and test-target scope; permission denials; model-external HMAC approvals; binding to environment instance and pre/post-state fingerprints; proposal and wall-clock expiry; frozen expired pending intents and recovery with a fresh approval; proposal/step budgets; idempotent replay whose authority is the adapter receipt; complete receipt fingerprints; human reconciliation through needs_review; HMAC checkpoints with an external monotonic high-water mark; crash-window recovery; versioned verification; cancellation; and termination. The current baseline is 103 offline tests.

Mastery checklist

  • I can explain the difference between environment state, observation, runtime state, and context.
  • I can write schema, scope, precondition, risk, idempotency, and evidence fields for an action.
  • I can explain why locator uniqueness, visibility, stability, event reception, and enabled state are runtime checks.
  • I can freeze VM, application, account, locale, window, and data initial state for a desktop task.
  • I can freeze base commit, dependencies, tests, and network policy for a coding task.
  • I can bind a high-risk write to short-lived approval with exact scope.
  • I can handle the crash window where a side effect happened but its checkpoint was not written.
  • I can check initial state, final state, trajectory, side effects, cost, and latency together.
  • I can run 103 tests and explain at least five negative cases.
  • I can identify when to fall back to a fixed workflow or human operation.

Primary references

TopicPrimary sourceHow this course uses it
Real web environments and functional correctnessZhou et al., WebArena; official repositoryInitial state, real sites, and functional final-state evaluation
Real computer environments and executable evaluationXie et al., OSWorld; official repositoryMachine initial state, cross-application state, and executable verifier
Real repository issue-to-patch tasksJimenez et al., SWE-bench (ICLR 2024); official repositoryBase commit, patch, FAIL_TO_PASS, and PASS_TO_PASS
Locators and action preconditionsPlaywright: Auto-waiting / actionabilityChecks for uniqueness, visibility, stability, event reception, enabled state, and more
Environment isolation and robust locatorsPlaywright: Best PracticesIsolation, user-visible behavior, semantic locators, and web-first assertions
Agent tools and human controlOWASP AI Agent Security Cheat SheetLeast privilege, untrusted external data, separate authorization for sensitive actions, and adversarial testing
Organization-level risk governanceNIST AI RMF and Generative AI ProfileRisk, measurement, human oversight, and why release evidence is more than one benchmark score

Course boundary

This course does not teach steps for a specific browser SDK, desktop product, or coding-Agent CLI. Those APIs change and do not define the control plane. It also does not treat one benchmark score as production capability: deployment still needs validation of identity, data, organizational process, concurrency, compliance, maintainability, and incident recovery.