tensorlake-opencode plugin redirects the agent’s hands (its file and shell tools) into a Tensorlake sandbox, so the model’s commands and edits run in an isolated environment you control rather than on your laptop.
The model: brain local, hands in the sandbox
OpenCode keeps running locally: the TUI, the model loop, and your session all stay on your machine. The plugin only intercepts the tool calls and routes them to a sandbox:apply_patch matters more than it looks. OpenCode’s built-in apply_patch writes to your local filesystem. The plugin shadows it (plugin version 0.3.0 and later) so a patch cannot bypass the sandbox.
webfetch and websearch are not intercepted. They stay local, since they don’t touch your filesystem.
Subagents (the task tool) run in their own OpenCode session but use the sandbox of the session that spawned them. See Subagents.
The sandbox itself runs on Tensorlake: fast boot, sub-second resume from a suspended snapshot, and state that persists across OpenCode restarts. See Sandbox lifecycle for the suspend/resume and snapshot model underneath.
Why route tool calls into a sandbox
- Isolation. The agent’s
bashandwritenever touch your host. A bad command, a runaway install, or anrmlands in a disposable environment, not your working tree. - Reproducible environment. Every session gets the same image, CPU, and memory regardless of what’s on the developer’s machine. Pin a custom image with the right toolchain once and every session inherits it.
- State that survives restarts. Sandboxes are named and persisted to disk, so a session reconnects to its sandbox across OpenCode restarts; a suspended sandbox resumes with
/tmp/workspace, installed deps, and warm caches intact. - Work that outlives the sandbox. Mount a Tensorlake filesystem or attach a hosted git repository, and the agent’s files survive sandbox deletion. See Persist work across sandboxes.
Prerequisites
- An OpenCode installation.
- A Tensorlake project API key. Sign up at cloud.tensorlake.ai, open your project, and create a key under API Keys. Personal Access Tokens are not supported.
- A supported platform. The Tensorlake SDK ships a native binary for macOS on Apple Silicon (Intel Macs are not supported), Linux x64 and arm64 (glibc and musl), and Windows x64.
Setup
1
Add the plugin to your OpenCode config
Add the package name to OpenCode treats bare names as npm packages and installs them into its own cache (
~/.config/opencode/opencode.json (create the file if it doesn’t exist):~/.cache/opencode/packages/). You don’t run npm install yourself.2
Log in
The plugin registers Tensorlake in OpenCode’s standard auth flow (plugin version 0.2.0 and later):Select Tensorlake and paste a project API key (it starts with
tl_apiKey_). OpenCode stores the key in its credential store next to your other provider credentials. If the key is wrong, the first tool call shows an error toast that tells you to log in again — no restart needed, just retry after logging in.CI / automation: set the TENSORLAKE_API_KEY environment variable instead. It wins over the stored key. Use a project API key; the key itself selects the organization and project.3
Start OpenCode
OpenCode started with TensorLake plugin.Lazy sandbox creation
The sandbox is created lazily, on the first intercepted tool call in a session, not when you launch OpenCode. If you start OpenCode and nothing appears to happen, that’s expected. A session that only uses
webfetch/websearch will never spin one up, because neither is intercepted.bash call the plugin provisions the sandbox. You’ll see a “Sandbox created” toast and new log lines:
uname -a will report Linux (the sandbox), confirming the command ran remotely rather than on your Mac.
Verify it’s working
Ask the model to write and read a file back:write call routes to sandbox.writeFile() and the read call to sandbox.readFile(), both over the SDK. The agent’s working directory inside the sandbox is /tmp/workspace.
Subagents
When the model uses thetask tool, OpenCode starts a subagent in a child session. The child session does not get its own sandbox. It shares the sandbox of the session that spawned it, all the way up to the root session of the tree. This mirrors how local subagents share the user’s working tree: the parent sees the subagent’s edits, and the subagent sees the parent’s.
- Deleting a subagent session deletes nothing. The sandbox belongs to the root session, and is torn down when that session is deleted.
- Deleting the root session waits for subagent tool calls that are still running, so nothing is terminated mid-write.
Persist work across sandboxes
By default a sandbox’s disk is ephemeral: deleting the session deletes its files. Two optional plugin settings let the agent’s work outlive the sandbox. You set them as plugin options inopencode.json, or as environment variables (the environment variable wins).
Persistent filesystem
Create a Tensorlake filesystem and name it in the plugin options:/tmp/workspace. Files the agent writes there persist in durable storage, survive sandbox deletion, and are visible to every other sandbox or tl fs mount that mounts the same filesystem. Set filesystemPath (or TENSORLAKE_FILESYSTEM_PATH) to mount it somewhere else.
A misspelled filesystem name blocks tool calls with a “Filesystem attach failed” toast instead of silently running against ephemeral storage.
Hosted git repository
To let the agent persist work through git, name a Tensorlake git repository. The repository is hosted in your Tensorlake project, not on GitHub. Only people with an API key for the project can see it or push to it.filesystem and gitRepo together. The agent then clones the repository onto the mounted filesystem, so the working copy survives sandbox deletion and the pushed commits live in the repository. If you also mount that filesystem on your machine, run git commands from one side only: concurrent writes to the same .git files lose data silently.
Configure the sandbox
The plugin has two kinds of settings:- Plugin options in
opencode.jsonchoose what the sandbox attaches to: a filesystem and a git repository. Each also has an environment variable, and the variable wins. - Environment variables decide what the sandbox looks like: its image, CPUs, memory, and disk. There is no config-file form for these; you set them in the shell, then launch OpenCode from that same shell.
The variables are read once, when the sandbox is created (the first intercepted tool call of a session). Set them before you run
opencode. Changing a variable in another terminal, or after the sandbox already exists, has no effect on the running session. Start a new session to pick up new values.How it fits together
Plugin options
Set these inopencode.json as the second element of the plugin entry: ["tensorlake-opencode", { ... }].
All variables
Making the settings persistent
Your API key persists on its own —opencode auth login stores it once. The filesystem and git settings persist in opencode.json. The sandbox-sizing variables are shell exports, so to apply the same config every time, add them to your shell profile (~/.zshrc or ~/.bashrc):
source ~/.zshrc) and every opencode session inherits them.
Use a custom image
TENSORLAKE_IMAGE is the most impactful setting for real work: it lets every OpenCode session start from an environment that already has your language runtimes, system packages, and project dependencies, so the agent isn’t reinstalling them on each session. Register an image, then point the variable at its name:
Troubleshooting
No sandbox starts when I launch OpenCode. Expected. The sandbox is created on the first tool call, not at launch. Ask the model to run a command (for example,Run: uname -a).
“Tensorlake login required” toast. Run opencode auth login, select Tensorlake, and paste a project API key. No restart is needed; retry the tool call.
Auth error (401/403) in the log. The stored key was revoked. Re-run opencode auth login with a fresh project API key.
“Filesystem attach failed” toast. The name in filesystem / TENSORLAKE_FILESYSTEM does not exist in this project. Create it with tl fs create <name> or fix the name.
tl fs unmount fails with volume_busy. A process still holds the mount, usually a shell whose working directory is inside it. Leave the directory (cd ~), close editors pointed at the path, then unmount.
Missing native binding for <platform>. Your platform is not supported by the Tensorlake SDK. See Prerequisites.
Anything else. Check ~/.local/share/opencode/log/tensorlake.log. If the file does not exist, the plugin never loaded.
Next steps
Plugin source
The full plugin: tool interceptors, session manager, and lifecycle handling.
Sandbox lifecycle
The suspend/resume and snapshot model that persists session state.
Build and Import Images
Build a custom image so every OpenCode session gets the same toolchain.
Filesystems
Durable storage the agent’s files survive in after the sandbox is gone.
Git repositories
Hosted repositories the agent can clone, commit, and push to.
Tool calls
The general pattern: expose sandboxes as tools to any LLM agent.