Skip to main content
Version: v3

Sandbox

TF Code can run every shell it spawns inside an operating-system sandbox rather than relying on the permission prompt alone. Permissions decide whether a command may run; the sandbox decides what a running command can reach on your machine.

With a profile enabled, an approved bash command can still be… well, bash — but it can only read the paths you allow, only write the paths you allow, and only reach the network destinations you allow. Anything else fails at the OS level, including nested shells and subprocesses the command starts.

note

The sandbox is off by default. When it is off, behaviour is identical to previous releases.

What is contained​

SurfaceCovered
bash tool✅
Plugin shell handlers✅
Plugin HTTP handlers✅
Plugin/JS $ shell✅
POST /session/{id}/shell✅
Subagents✅ inherit the session profile
Direct file tools (read/write/edit)❌ unchanged — OS file I/O in-process, tracked as a separate follow-up

The sandbox applies to shell execution, not to the TF Code process itself. Providers, the language server, MCP servers, browser automation and computer use are outside the boundary — they are daemon-owned integrations, not agent-issued commands.

Configure​

The sandbox section is read only from trusted configuration:

  • global config files (~/.config/tfcode/config.json, tfcode.json, tfcode.jsonc)
  • the file at TFCODE_CONFIG
  • enterprise managed config (/Library/Application Support/tfcode on macOS, /etc/tfcode on Linux)

A repository's own tfcode.json, .tfcode/tfcode.json, or inline config cannot enable, disable, or widen the sandbox. That is deliberate: cloning an untrusted repository must never change your containment policy.

{
"sandbox": {
"enabled": true,
"read": ["workspace"],
"write": ["workspace", "tmp"],
"network": "proxied",
"hosts": ["registry.npmjs.org", "*.github.com"],
"allowPlainHttp": false
}
}
KeyTypeDefaultMeaning
enabledbooleanfalseTurn the sandbox on
readstring[]["workspace"]Readable scopes: workspace, tmp, cache, home
writestring[]["workspace"]Writable scopes — same values
networkstring"none"none, proxied or open
readRootsstring[][]Extra absolute paths to read (e.g. a custom toolchain)
hostsstring[][]Destinations allowed when network is proxied
allowPlainHttpbooleanfalseAllow plain HTTP (not just HTTPS) to hosts

Unknown keys are rejected rather than ignored, so a typo can never silently drop a restriction.

Scopes​

ScopeResolves to
workspaceThe session's project directory
tmpThe system temp directory
cacheTF Code's cache directory (~/.cache/tfcode or XDG equivalent)
homeYour home directory

System binaries, libraries and DNS configuration are always readable so that ordinary tools work. A small set of common toolchain directories under your home are also readable by default — ~/.cargo/bin, ~/.cargo/registry, ~/.cargo/git, ~/.rustup/toolchains, ~/.bun/bin, ~/.nvm/versions, ~/.pyenv/versions, ~/.local/bin. Everything else needs an explicit entry.

Writes are the exception in the other direction: only the declared scopes plus /dev/null are writable. Reads under home are not granted by default — ~/.ssh, .env files and other credentials are unreadable unless you choose home or add a readRoots entry.

caution

read: ["home"] and write: ["home"] are powerful. Reading home exposes credentials to the model; writing home lets an approved command modify dotfiles and configuration. tfcode sandbox doctor warns when either is enabled.

Network​

ModeBehaviour
noneEvery socket is refused — external and loopback. Default.
proxiedOnly hosts are reachable, through a local audited broker.
openNo network restriction (filesystem containment still applies).

Proxied egress​

In proxied mode the sandbox exposes exactly one loopback port — a broker owned by the TF Code process — and points HTTP_PROXY / HTTPS_PROXY / ALL_PROXY at it. Direct connections are refused by the OS, including raw TCP and UDP. That means:

  • an environment variable alone cannot be "worked around" by a program that ignores proxies;
  • the broker validates the destination hostname against hosts before connecting;
  • *.example.com matches subdomains but not example.com itself;
  • destinations that resolve to private, loopback, link-local or unspecified addresses are refused, so a name cannot be used to reach the host itself;
  • HTTPS stays end-to-end — the broker opens a tunnel and does not decrypt or log payloads;
  • the broker lives only as long as the command that owns it.

Plain HTTP is off unless allowPlainHttp is set; HTTPS via CONNECT is the default path. With an empty hosts list, proxied denies every destination — useful as a "no network but keep the option explicit" posture.

Typical registry/build setup:

{
"sandbox": {
"enabled": true,
"read": ["workspace", "cache"],
"write": ["workspace", "cache", "tmp"],
"network": "proxied",
"hosts": ["registry.npmjs.org", "*.npmjs.org", "crates.io", "static.crates.io", "github.com", "*.githubusercontent.com"]
}
}

cargo, npm, pip and git over HTTPS all work through the broker when their hosts are listed.

Per-session behaviour​

The policy is snapshotted when a session is created and inherited by its subagents. A later config change can only narrow an existing session — turning the sandbox off, removing a scope, shrinking the host list — never widen it. A session therefore cannot gain reach because you edited config mid-conversation.

Changing the profile for new sessions is a config edit; sessions already running keep their snapshot (subject to narrowing).

Backends​

PlatformBackendStatus
macOSSeatbelt (sandbox-exec with a generated SBPL profile)Verified: reads, writes, descendants, network none, proxied, abort/timeout cleanup
LinuxLandlock (filesystem) + seccomp (sockets)Implemented; none/open intended. proxied is refused until it is verified on a Linux host
Windows—No backend: an enabled profile refuses to run and doctor reports it as unavailable

Refusing is intentional. If a requested axis cannot be enforced on the current platform, TF Code returns an error and does not run the command unsandboxed. There is no silent downgrade.

On Linux, a kernel with Landlock ABI 3 or newer is required for filesystem enforcement. Seccomp is used to deny socket creation for network: none.

Check your setup​

tfcode sandbox doctor

Reports the backend, per-axis availability, the effective policy for the current directory and the resolved read/write roots:

tfcode sandbox doctor
OK backend: seatbelt (available)
OK filesystem read/write containment
OK network: none
OK network: proxied
OK network: open
sandbox-exec present; SBPL read/write/network rules verified

policy for /Users/you/project:
read: [Workspace]
write: [Workspace]
network: None

no problems detected.

Machine-readable output for scripts and CI:

tfcode sandbox doctor --json
tfcode sandbox doctor --dir /path/to/project --json

doctor exits non-zero when the profile is enabled and something is wrong — an unavailable backend, an unenforceable axis, or an empty proxied allow list.

Interaction with permissions​

The sandbox does not replace permissions; the two layers stack:

  1. Permissions decide whether the agent may call the tool, and may prompt you.
  2. The sandbox decides what the approved command can touch.
{
"permission": { "bash": "ask" },
"sandbox": { "enabled": true, "write": ["workspace"], "network": "none" }
}

Here you still approve each shell command, and an approved command is additionally limited to writing inside the workspace with no network. --auto, plan mode, headless runs and "always allow" replies do not widen the sandbox.

An external_directory permission grant lets a command run with a working directory outside the project, but it does not grant sandbox write access there — you have asked for OS enforcement, so the permission grant only skips the asking flow.

MCP and external tools​

MCP tools, LSP servers and the browser automation run in the TF Code process, not inside a sandboxed shell. They are governed by permissions and policies as before. If you need a command that reaches the network, run it through bash so it inherits the sandbox profile.

Troubleshooting​

A build tool cannot read its own cache. Add the toolchain path to readRoots, for example:

{ "sandbox": { "enabled": true, "readRoots": ["/opt/homebrew", "~/.deno"] } }

doctor reports the backend unavailable. On macOS, check /usr/bin/sandbox-exec exists. On Linux, check your kernel supports Landlock:

grep landlock /boot/config-$(uname -r) 2>/dev/null || dmesg | grep landlock

A command fails with "Operation not permitted" writing somewhere expected. That path is outside read/write. Add the narrowest scope that covers it (prefer a readRoots entry or tmp/cache over home).

Network calls hang or return 000 in proxied mode. The destination host is not in hosts, or it resolved to a private address. Check tfcode sandbox doctor --json for the effective host list.

Spotting the denial. Sandbox denials surface as the tool's own error output (Operation not permitted, connection failure, or the broker's message). They are not permission prompts — the model sees the failure and must adapt.