A coding agent is asked to fix a flaky login test. It reads the repository, edits three files, runs the test suite and reports success. Two hours later a colleague finds three problems. The "fix" also changed a shared fixture used by an unrelated service. The test run used a build directory left behind by a different task. And the working tree the agent edited was the same one a second agent was using at the time. Nothing in the model's reasoning was wrong in a way you could point to. The environment let two jobs write to the same place, and it let a sentence saying "all tests pass" stand in for evidence.
This article is about the environment around a coding agent: where it runs, what it can touch, how a human watches it, and how its work gets back out. We separate two questions that are often blurred together. The first is what the agent needs in order to work, which is a filesystem, a shell and some tools. The second is what a human needs in order to trust the result, which is visibility, a way to intervene, and a diff to review. A headless container answers the first question well. A browser IDE such as Eclipse Theia answers the second. Most teams need both, attached to the same workspace but built as separate pieces.
What an agent actually needs from its environment
Strip away the product names and an agent's loop is small: read some files, change some files, run a command, look at the output, decide what to do next. Every step of that loop is an operation on a machine, so the environment is the set of guarantees the machine gives the loop. It is worth writing those guarantees down, because each one maps to a failure you can later diagnose.
- A private, writable filesystem. The agent must be able to create, edit and delete files without any chance that another task sees the half-finished state. This is the single most important property, and most "the agent corrupted my checkout" stories are violations of it.
- A shell with the project's toolchain. Compilers, package managers, test runners and linters at the versions the project expects. If the agent has to guess the Node or Python version, half of its failures will be environment failures that look like code failures.
- Language intelligence, optionally. A language server gives the agent diagnostics, symbol references and rename operations. These are cheaper and more reliable than grepping, and they return structured results. They are an optimization, not a requirement, but they change how much context the agent burns on navigation.
- A network policy. Installing dependencies needs some outbound access. Exfiltrating a secret needs outbound access too. The policy has to be decided per workspace, not inherited from whatever the host happens to allow.
- Resource limits. CPU, memory, process count and disk quota. A runaway test or a fork bomb in a generated script should hurt one workspace, not the machine.
- A way to be stopped and inspected. You need to kill a task, freeze it, read its files after the fact and, when needed, attach a human to it.
Notice what is missing from the list: a graphical display. The model does not need pixels to edit a file. Agents typically drive the workspace through a tool protocol that exposes operations such as read a file, write a file, list a directory and run a command. Everything on this list can be delivered by a plain Linux process tree with a mounted directory. That observation is what makes headless operation the right default.
Headless first, browser IDE second
A headless environment has no editor, no window and no human attached. You start it from an API call, it runs to completion or until it is killed, and it leaves behind a filesystem and a log. Headless workspaces are cheap to start, trivially scriptable and easy to run in parallel. Their cost is opacity. When something looks wrong you are reading logs after the event, and a log is whatever the author of the tooling decided to record.
A browser IDE exposes the same workspace through a web frontend. A person can open the files the agent is editing, see the diagnostics from the language server, run a command in a terminal that sits in the same container, and look at the version-control view to see exactly what has changed. It turns "the agent says it is done" into something you can inspect in a minute rather than reconstruct from a transcript.
The design decision that matters is the relationship between the two. The IDE is a view onto the workspace. It is not where the workspace lives, and the agent does not run inside it. Both the agent and the IDE backend attach to the same directory, and either can be absent. If you build it the other way, with the agent living inside an interactive IDE session, you inherit every fragility of an interactive session: a closed browser tab that kills a task, an extension that blocks on a dialog nobody can see, a language server that restarts and loses the agent's place.
Isolation layers and what each one buys
"Run it in a sandbox" hides a range of very different guarantees. It helps to name the layers, what each one separates and what it leaves shared.
| Isolation layer | Files separated | Processes separated | Kernel shared with host | Start-up cost | Reasonable use |
|---|---|---|---|---|---|
| Shared checkout | No | No | Yes | None | One agent, one person, a throwaway repo |
| Git worktree | Working tree and index, not the object store or refs | No | Yes | Very low | Trusted code, parallel branches on one machine |
| Local clone in its own directory | Yes, including refs | No | Yes | Low | Trusted code that must not touch the original repository |
| Container with a bind mount | Only what is mounted | Yes (namespaces, cgroups) | Yes | Low to moderate | Most agent tasks, including dependency installs |
| Container under a user-space kernel or microVM | Yes | Yes | No, or a much smaller surface | Moderate | Untrusted code, multi-tenant hosting |
| Separate remote machine | Yes | Yes | No | Highest | Hardware-specific tests, strict data boundaries |
The start-up column is qualitative on purpose. Real numbers depend on image size, storage driver, whether layers are cached and what the project does on boot. Measure on your own infrastructure before you decide that a layer is "too slow".
Two distinctions in the table deserve a closer look. The first is worktree versus clone. A git worktree is attractive because it shares the object database with the main repository, so creating one is nearly instant and uses little disk. The same sharing is the catch. Branch names and refs are common to all worktrees, a given branch can be checked out in only one of them, and the worktree's .git is a small file that points back to a directory inside the main repository. If you mount only the worktree directory into a container, git inside the container cannot find its metadata. You either mount the common git directory as well, which weakens the isolation you were paying for, or you use a local clone, which costs more disk and gives the task a fully independent repository.
The second distinction is container versus a stronger boundary. A container is a set of kernel features (namespaces, control groups, capability and syscall filtering) applied to ordinary processes. The kernel is shared. For code your team wrote, running in a repository you trust, that is usually acceptable. When an agent installs arbitrary packages, executes scripts it generated from untrusted input, or you host tasks for people who do not trust each other, a kernel vulnerability becomes part of your threat model. That is the point at which a user-space kernel or a lightweight virtual machine earns its overhead.
Where a browser IDE such as Theia fits
How it is built
Eclipse Theia is an open-source framework for building IDEs that run in a browser or as a desktop application. The part relevant here is its split architecture. The frontend is a web application. The backend is a Node.js process that owns the filesystem, the terminals and the language servers, and the two communicate over a persistent connection, typically WebSocket with a JSON-RPC style protocol. Because the backend is the thing that touches files, you can run it on the machine or in the container where the workspace lives and expose only its web port. Theia speaks the Language Server Protocol and the Debug Adapter Protocol, and it can load extensions that follow the VS Code extension API, usually from the Open VSX registry. Check the current documentation for the exact extension compatibility, since that surface moves between releases.
Alternatives follow the same shape. Browser editors based on the VS Code codebase, such as code-server and OpenVSCode Server, also run a backend next to the files and serve a web frontend. The reasoning in this article does not depend on which one you pick. What matters is that the backend runs beside the workspace and that the frontend is disposable.
What the human uses it for
People attach to an agent's workspace for four reasons, and it is worth designing for each one explicitly.
- Watching. File watchers refresh open editors as the agent writes, so you see edits appear without any special integration.
- Reviewing. The source-control view shows the diff against the base branch. Reviewing the diff, rather than the agent's description of it, is the point of the exercise.
- Reproducing. A terminal in the same container lets you re-run the failing command in exactly the environment the agent used, with the same environment variables and caches.
- Taking over. When the agent is stuck, you fix the last ten percent by hand in the same tree, then let it continue or stop it.
The IDE is a remote shell with a web page on it
An IDE backend can read any file the workspace user can read and run any command that user can run. Treat it with the same care as an SSH server. Put it behind an authenticating reverse proxy, use per-workspace addresses or paths that cannot be guessed, check the WebSocket origin, and use short-lived credentials. Never mount the container runtime's control socket into the workspace, because that is equivalent to giving the agent root on the host. Decide in advance whether the IDE may install extensions at runtime: an extension runs with the backend's privileges, so a freshly installed extension is new code in your trust boundary.
A worked example: one task, one workspace
Here is a concrete flow for a task identified as fix-login-timeout. The script below creates an independent clone, starts a locked-down container that can see only that clone, and leaves the IDE backend as an optional second process attached to the same directory. It is a sketch to adapt, not a finished product; the network name, image names and the agent command are placeholders you would replace with your own.
#!/usr/bin/env bash
set -euo pipefail
TASK_ID="$1" # e.g. fix-login-timeout
BASE_BRANCH="${2:-main}"
REPO="$(git rev-parse --show-toplevel)"
WORKSPACE="$HOME/agent-workspaces/$TASK_ID"
# 1. An independent clone: own refs, own index, own object store.
git clone --quiet --local --branch "$BASE_BRANCH" "$REPO" "$WORKSPACE"
git -C "$WORKSPACE" switch --quiet -c "agent/$TASK_ID"
# 2. The agent runs in a container that sees only this directory.
docker run -d --rm \
--name "agent-$TASK_ID" \
--user 1000:1000 \
--read-only \
--tmpfs /tmp:rw,size=512m \
--cap-drop ALL \
--security-opt no-new-privileges \
--pids-limit 512 \
--memory 4g \
--cpus 2 \
--network agent-egress \
-v "$WORKSPACE:/workspace:rw" \
-w /workspace \
agent-runtime:latest \
agent-run --task "$TASK_ID"
# 3. Optional: an IDE backend on the SAME directory, reachable only
# through the authenticating proxy, never published on a public port.
docker run -d --rm \
--name "ide-$TASK_ID" \
--user 1000:1000 \
--cap-drop ALL \
--security-opt no-new-privileges \
--network ide-internal \
-v "$WORKSPACE:/workspace:rw" \
ide-backend:latest
echo "workspace: $WORKSPACE"
Read it as a set of decisions rather than a recipe.
- The clone makes the task's branch, index and objects private. Nothing the agent does with git can move a ref in the original repository. Getting the work back out is a separate, explicit step that you control.
- The agent container is read-only except for the mounted workspace and a small scratch filesystem. A tool that tries to write to the image's system directories fails loudly instead of silently changing the environment for the next task.
- Capabilities are dropped, privilege escalation is disabled and the process count and memory are capped. These are the cheap controls that stop a runaway loop from becoming a host incident.
- The agent is attached to an egress-controlled network. In practice that is a network where outbound traffic goes through a proxy that allows your package registries and your model endpoint and nothing else. Without such a proxy the flag is decoration.
- The IDE backend is a separate container on a separate network, sharing only the workspace directory. If it crashes, the agent continues. If the agent crashes, the IDE still shows the tree.
The part that is not in the script matters most. When the agent reports that it is finished, a supervisor outside the container checks out the branch, runs the project's test suite itself, and inspects the diff. The agent's statement is treated as a claim, and the exit code of a command the supervisor ran is treated as evidence. This is the same principle a production agent stack should apply: isolated workspaces for every task, and verification before completion rather than trust in a summary. Only after that check does a person, or a policy, approve pushing the branch and opening a pull request. Then the workspace is deleted, because workspaces that live for weeks drift away from the base branch and quietly turn into pets.
Failure modes you will meet
These are the problems that tend to appear once more than one task runs at a time. Each has a plain fix.
- Worktree metadata pointing outside the mount. Git inside the container fails with a "not a git repository" style error. Use an independent clone, or mount the common git directory and accept the weaker boundary.
- Shared caches that are not actually shared safely. Two tasks writing to the same package or build cache can corrupt each other. Give each workspace its own cache directory, or mount a shared cache read-only and let each task write to an overlay.
- Port collisions. Many dev servers want the same default port. Assign ports per workspace from a registry, or give each workspace its own network namespace so the collision cannot occur.
- Zombie processes after cancellation. A task is cancelled but its test runner or browser keeps running. Run a minimal init process as PID 1 in the container, and kill the whole container rather than the one process.
- Disk exhaustion. Fifty abandoned workspaces, each with dependencies installed, will fill a disk. Give every workspace a time-to-live and a quota, and delete on completion by default.
- Secrets in the environment. An environment variable that a test helper prints becomes part of a log and then of a model's context. Pass credentials as narrowly scoped, short-lived tokens, and scrub known secret patterns from logs before anyone or anything reads them.
- Symlinks and mounts that escape. A symlink inside the workspace pointing at a host path is harmless if only the container follows it, and dangerous if a host-side tool does. Do your verification and export steps against a copy or inside a container too.
- User ID mismatch on bind mounts. Files created by the container are owned by an unexpected user on the host, or the container cannot write at all. Pick one numeric user for the container and set ownership of the workspace to match when it is created.
- The IDE installing something at runtime. An extension update changes behavior between two runs of the same task. Pin the extension set in the image and disable runtime installation in shared environments.
When not to build this
A full environment per task is real engineering work, and some situations do not justify it.
- One developer and one agent on a laptop, working on a branch with a clean tree, is adequately served by a branch and the ability to discard changes. A container adds friction without removing a risk that exists.
- If no person will ever look at the workspace, a browser IDE is overhead. Skip it, keep the logs and the final diff, and add the IDE the first time someone says they wish they could see what happened.
- Tasks that only touch documentation or configuration with no code execution do not need dependency installs or a toolchain, so the isolation question is smaller.
- Work that depends on hardware, a GPU or a specific physical device cannot be moved into a generic container image. Treat that as a separate machine problem.
- When data sensitivity forbids a remote IDE at all, for example because the source cannot leave a particular network, the web frontend is a liability. Keep the agent headless and review the diff through your existing code-review tool.
Decision checklist and common mistakes
Before you ship an agent environment, answer these in order. A "no" on any early item is cheaper to fix than a late one.
- Can two tasks ever write to the same file path? If yes, separate them first.
- Does the task execute code you did not write, such as installed dependencies or generated scripts? If yes, use at least a container, and consider a stronger boundary for untrusted sources.
- What can the workspace reach on the network, and who decided that? Write the allowed destinations down.
- Which credentials exist inside the workspace, how narrow are they and when do they expire?
- Who verifies completion, and does verification run outside the agent's control?
- How does a human attach, and what happens to the task if they close the tab?
- What deletes the workspace, and when?
The mistakes that recur in practice:
- Building the IDE first because it is visible, then discovering that the agent depends on it being open.
- Mounting the whole home directory or the container socket "just to make it work".
- Accepting the agent's report as the result instead of rerunning the tests independently.
- Giving every task the same long-lived access token because it is easier to configure.
- Keeping workspaces around "in case we need them", which turns scratch space into undocumented state.
- Treating isolation as binary. The question is always what is separated from what, and which attacker or accident you are separating it from.
Questions teams ask, and what to do on Monday
Do we need an IDE at all if the agent works fine? Not for the agent. You need it for the people who must trust, debug and occasionally correct the work. If the work is reviewed only as a diff in your existing review tool, you may never need one.
Is a container enough? For trusted repositories and ordinary dependency installs, usually yes. For untrusted inputs or multiple tenants, assume a shared kernel is part of your attack surface and evaluate a stronger boundary.
Can the agent run inside the IDE? It can, and some products are built that way. You then take on the IDE's session lifecycle as part of the agent's reliability. If you do it, make sure long tasks survive disconnects.
What should be logged? The commands run, their exit codes, the final diff, and the verification result. Avoid logging full environments, since those carry secrets.
If you want something concrete to do next week, this sequence delivers most of the value in the shortest time.
- Give each agent task its own clone or worktree and its own branch, and stop sharing a checkout today.
- Put the task in a container with a read-only root filesystem, dropped capabilities, and memory and process limits.
- Move test execution for completion checks out of the agent's control: the supervisor runs the suite and reads the exit code.
- Add a time-to-live that deletes finished workspaces.
- Only then add a browser IDE backend on the same directory behind your existing authentication, and watch which of the four uses (watching, reviewing, reproducing, taking over) people actually reach for.