Skip to content
mentoor

Topic 2 of 5 · 4 min read

The environment an agent acts in

Goal: List what an agent can read, change and reach in a described environment and mark which of its actions cannot be undone.

The environment is everything an agent's tools can read, change or reach, and it sets both what the agent can do for you and what it can break. The same model is harmless in a sandbox and dangerous with production credentials.

Check yourself · 1 of 3

What mainly decides how much damage an agent can do?

Choose one answer

Why it matters

People judge agents by the model. The better question is what the agent is connected to. A model that can only read files in a scratch folder can waste your time. A model with a shell, your cloud credentials and a payment API can cost real money. Risk comes from the tools and permissions, not from how clever the model is.

How to map an environment

For any agent, write three lists.

  1. Reads. Files and folders, environment variables, databases, web pages, email, tickets. Anything here can also leak: the agent may copy a secret into a log or a prompt.
  2. Writes. Files it can edit, commands it can run, records it can update, messages it can send, money it can move.
  3. Reach. Networks and accounts: can the shell call the internet, push to git, open a database connection, use the logged-in browser profile?

Then mark each write as reversible or irreversible. Editing a tracked file is reversible: version control undoes it. Sending an email, running DROP TABLE, force-pushing, deleting an untracked folder, charging a card or posting to a public channel is not. Irreversible actions are where you add a human approval, a dry run or a backup.

Prefer narrow tools over broad ones. A tool called refund_order(order_id, amount) with a cap is safer than a raw SQL shell, even though the shell can do the same job.

Before and after

A weak setup for a "tidy my repo" agent:

tools:    shell (full access)
cwd:      home directory
secrets:  .env loaded, cloud keys in shell profile
network:  open
approval: none

A scoped version of the same agent:

tools:    read_file, edit_file, run_tests (inside the repo only)
cwd:      a git worktree copy of the project
secrets:  none exposed
network:  off
approval: required before any delete or git push

The agent is just as useful for tidying code, and almost everything it could damage is gone or recoverable.

What goes wrong

  • Ambient credentials. The shell inherits keys from your profile, so the agent can touch systems you never meant to give it.
  • Irreversible steps without a gate. A deletion or a send happens before anyone looks.
  • Untrusted content in the environment. A web page, issue or email the agent reads can contain instructions aimed at the agent.
  • No record. Without a log of reads and writes you cannot tell what changed or recover from it.

Examples

Mapping a support agent

Reads: order database, customer email thread. Writes: draft reply, refund_order up to a fixed amount. Reach: internal API only, no open web. Irreversible: sending the reply and issuing the refund. Gate: a human approves sends, and refunds above the cap are refused by the tool itself.

The environment hidden in a shell

env | grep -i key

If an agent with a shell can run this, every key in the process environment is readable by it and by anything it pastes the output into. Start agent shells with a clean environment and pass only what the task needs.

Key points

  • The environment is what the agent's tools can read, write and reach, and it sets power and risk more than the model does.
  • List reads, writes and reach separately, because reading can leak and writing can break.
  • Mark every write as reversible or irreversible and put approval or backups on the irreversible ones.
  • Narrow tools with caps are safer than a general shell that can do the same thing.
  • Content the agent reads, such as web pages and emails, is part of the environment and can carry hostile instructions.

Common mistakes

  • Treating the model as the only thing to evaluate and ignoring what its tools can reach.
  • Letting the agent run in your real home directory or main checkout instead of a scratch copy.
  • Giving one broad tool, such as a raw SQL shell, when two narrow tools would do the job.
  • Forgetting that pages, tickets and emails the agent reads can contain instructions.

Check yourself · 2 of 3

Which of these agent actions is hardest to undo?

Choose one answer

Check yourself · 3 of 3

A "tidy my repo" agent has a full shell in your home directory with cloud keys in the profile. What is the best first change?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic