Skip to content

Write code with file tools in the sandbox, and check it in the sandbox's browser - #70

Merged
abhishek-anand merged 10 commits into
mainfrom
feat/code-edit-tools
Dec 3, 2026
Merged

abhishek-anand merged 10 commits into
mainfrom
feat/code-edit-tools

Conversation

@abhishek-anand

Copy link
Copy Markdown
Collaborator

Coding tasks wrote files through shell heredocs, could not look at their own screenshots, and could not open the page they built: the sandbox browser refused 127.0.0.1.

  • write_file and edit_file write in the sandbox through its kernel (one files session, run as a function so nothing is left in it). An edit replaces exact text found once, or every place with all=true, and returns the changed lines numbered. A relative path starts in the shell's directory.
  • Each change is a file event with the file as it now is (first 64K characters), and a command run in /workspace is followed by a files_changed event naming what it made. These feed the Code tab (next PR).
  • GET /api/sandbox/file?path= reads a text file from the sandbox for that tab. Read-only, text only.
  • file_view looks at a picture under /workspace, /app, /tmp or /root in the sandbox, resized there.
  • With browser.mode "computer", Chrome runs on the sandbox's desktop, so its loopback is the sandbox. The assistant may now open a server it runs there (browser_open http://127.0.0.1:8765/), and pages may move within that same origin. Ports of the sandbox's own services (8222, 8888, 3000, 5900) and the admin port stay closed, as do private networks, page-led navigation to any other loopback port, and loopback in every other browser mode.
  • The room test sized its small room as a fixed 6000 tokens, which every new instruction line broke. It now sizes the room from the instructions.

Tests: tests/test_code_tools.py (a fake kernel that runs the real script), full suite 1288 passing.

…open its own server in its browser

write_file and edit_file write in the sandbox through its kernel, where shell heredocs broke on quoting, and
each change is an event the app can show. file_view reads a picture the assistant made in /workspace. On the
sandbox's desktop, browser_open may open a server the assistant runs there, and pages of that server only; the
sandbox's own services and every other local address stay closed. The room test sizes its small room from the
instructions, so a new instruction line no longer breaks it.
…e the task works

A Code tab appears once a task writes a file: a tab per file, read-only, with the lines an edit changed marked
and brought into view; a file a command made is read from the sandbox when opened. While a task of the open
thread works, the panel turns to its terminal for a command, its screen for the browser and its code for an
edit. A tab the owner picks holds for the rest of that task.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical same-origin navigation bypass remains unresolved, alongside unbounded file reads and regressions in file editing and attachment viewing.

6 open issues
What changed in this PR

Adds sandbox file tools and local web previews so coding tasks can create, edit, and inspect their work.

Changes:

  • Adds file writing, exact-text editing, change events, and a text-reading endpoint.
  • Enables sandbox image viewing and loopback browsing in computer mode.
  • Adds coverage and makes the context-capacity test adapt to instruction size.
File Description
tests/​test_parallel.py Sizes test capacity from instructions.
tests/​test_code_tools.py Tests file tools, images, browsing, and file reads.
coderunner/​server/​gateway.py Adds the sandbox text-file endpoint.
coderunner/​sandbox/​files.py Implements kernel-backed file operations.
coderunner/​browser/​broker.py Allows selected sandbox loopback servers.
coderunner/​agent/​tools.py Registers file tools and emits change events.
coderunner/​agent/​loop.py Updates coding and preview instructions.

Review effort: Balanced

Comment thread coderunner/browser/broker.py Outdated
Comment on lines +1299 to +1302
origin = f"{host}:{port}"
if chosen:
self._built.add(origin)
return origin in self._built
Comment thread coderunner/agent/tools.py
Comment on lines +241 to +243
except (httpx.TransportError, OSError):
if last or not await brought_back():
return SANDBOX_DOWN
Comment thread coderunner/agent/tools.py
show_file(ctx, path, found, op="edited", line=line, until=line + new.count("\n"))
times = f" ({found['count']} places)" if found.get("count", 1) > 1 else ""
return (f"Edited {path} at line {line}{times}; it has {found.get('lines', 0)} lines now:\n"
+ sandbox_files.excerpt(found.get("body", ""), line, new))
Comment thread coderunner/agent/tools.py
Comment on lines +1109 to +1112
wanted = str(args.get("path") or "").strip()
if wanted.startswith(SANDBOX_ROOTS) and getattr(svc, "sandbox", None) is not None and \
not files.folders.inside(wanted):
return await view_own(wanted, ctx)
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(a["content"], encoding="utf-8")
elif a["op"] == "edit":
text = p.read_text(encoding="utf-8")
Comment thread coderunner/sandbox/files.py Outdated
Comment on lines +65 to +70
raw = p.read_bytes()
if a["op"] == "read" and b"\0" in raw[:8192]:
return {"error": "binary", "size": len(raw)}
body = raw.decode("utf-8", errors="replace")
out.update(lines=body.count("\n") + (1 if body and not body.endswith("\n") else 0), size=len(body),
body=body[:a["shown"]], cut=len(body) > a["shown"])
…r write overtook

The write's tool event comes before its file, so with nothing to show the panel
went to Screen and stayed there. A live file now applies the follow, unless the
owner picked a tab. A read of a file a command changed is dropped if a newer
write of that file came while it was read.
Show the code a task writes in a Code tab, and follow the task across the panel
@abhishek-anand
abhishek-anand merged commit da46f93 into main Dec 3, 2026
10 checks passed
@abhishek-anand
abhishek-anand deleted the feat/code-edit-tools branch December 3, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants