Skip to content

Agent tools in the SDK

sandbox.tools holds the tools a coding agent needs, in all five SDKs. Their answers are short and numbered, and they are cut to a token budget:

Tool What it returns
view(path, start, end) Numbered lines of a file
search(pattern, path) Matches with file and line
repo_map(path) An outline of a repository: files, classes and functions
apply_patch(patch, verify=) Applies a unified diff. With verify, it also runs a test or build command, so the edit and its check are one call.
run(cmd) The exit code, what a test runner or compiler reported, then the output cut to the budget. Error lines and the end of the log are kept.
diagnostics(path) Language-server diagnostics for a file

A patch that does not apply, or a missing file, comes back as an error whose text says what to fix.

from svm import Sandbox
from svm.agent_tools import AgentTools
PATCH = """--- a/calc.py
+++ b/calc.py
@@ -1,2 +1,2 @@
def add(a, b):
- return a - b
+ return a + b
"""
with Sandbox.create(template="base") as sandbox:
sandbox.files.write("/tmp/app/calc.py", "def add(a, b):\n return a - b\n")
tools = AgentTools(sandbox, cwd="/tmp/app") # or sandbox.tools with cwd= on each call
print(tools.view("calc.py").text)
print(tools.search("def add").text)
print(tools.repo_map().text)
print(tools.apply_patch(PATCH).text)
print(tools.command("python3 -c 'from calc import add; print(add(2, 3))'").text)
sandbox.lsp.install("python") # diagnostics come from a language server
print(tools.diagnostics("calc.py").text)

A sandbox can run MCP servers from the platform catalog behind its own MCP gateway. Turn them on at create with mcp_servers. Hand the gateway URL and its token to any MCP client. The token is a secret, and it expires, so fetch it when you connect.

import json
import urllib.request
from svm import Sandbox
# Server names come from the platform catalog ("time" and "fetch" need no secrets).
servers = [{"name": "time", "catalog_id": "time"}, {"name": "fetch", "catalog_id": "fetch"}]
with Sandbox.create(template="base", mcp_servers=servers) as sandbox:
url = sandbox.get_mcp_url()
token = sandbox.get_mcp_token() # send it as X-Traffic-Access-Token, not Authorization
print("gateway:", url)
request = urllib.request.Request(url, headers={"X-Traffic-Access-Token": token})
with urllib.request.urlopen(request) as response:
print(json.load(response)) # the servers behind the gateway
# An MCP client sends JSON-RPC to f"{url}/time" with the same header.

No MCP server starts unless the sandbox asks for it. A new sandbox has none. Tool rules on the gateway can require an approval for risky tools; sandbox.mcp_approvals lists and decides pending approvals.