/sandbox/files/library.
This guide shows how to wire your own agent loop into a Sandcastle. There are two ways to do it — pick the one that fits your architecture. The Sandcastle is the same either way; what changes is where the loop runs.
The Sandcastle is the execution environment — your agent never has to touch our infra directly. You either run your loop inside it and let the agent use the filesystem and tools natively, or run your loop in your own infra and execute commands inside the Sandcastle remotely over the Sandcastle API.
Prerequisites
| What | Where |
|---|---|
| TextQL API key | Settings → Developers → API Keys. Scopes the Sandcastle to your org and member, and gates the Context Library mount by your OWNERS permissions. |
| Model API key | Whichever LLM provider drives your loop (e.g. Anthropic). For the agent-inside mode this must be reachable through the Sandcastle’s egress proxy — see Outbound network. |
| Base URL | https://app.textql.com (or your dedicated/self-hosted host). |
/v2/sandcastles and authenticate with Authorization: Bearer <TEXTQL_API_KEY>.
Choose your topology
Agent loop outside
Your loop runs in your infra. You boot a Sandcastle and execute commands inside it remotely. Best when you already own the orchestration, want your loop next to your other services, or need to fan one loop across many Sandcastles. Fully supported today.
Agent loop inside
Your loop runs inside the Sandcastle. Your orchestrating code just boots the Sandcastle, pushes the agent, and starts it. The agent then reads/writes the filesystem and calls tools natively — no round-trip per step. Possible today via
exec; not yet a packaged template.Option A — Agent loop outside the Sandcastle
This is the “virtual bash tool” model: the loop lives in your orchestrating code and treats the Sandcastle as a remote execution + filesystem backend. Every tool call your model makes becomes an API call against the Sandcastle.Start (or restart) a Sandcastle
sandbox_id to resume a specific Sandcastle; omit it for a fresh one. The Sandcastle is keyed to your member, and its /sandbox/files/library mount is pruned to what your OWNERS permissions allow.Wire each tool the model can call to an endpoint
| Model tool | Sandcastle endpoint | Notes |
|---|---|---|
bash(cmd) | POST /v2/sandcastles/:id/exec | Fresh process per call (no shared shell state). kind: "bash" or "python". |
python(code) | POST /v2/sandcastles/:id/execute | Stateful kernel — variables and dataframes persist across calls. |
read_file / write_file / ls | GET/POST/DELETE /v2/sandcastles/:id/files… | Upload, download, list, delete files in the working dir. |
query_connector | POST /v2/sandcastles/:id/query | Runs SQL/TQL against an org connector and lands a dataframe in the kernel. |
Option B — Agent loop inside the Sandcastle
Here the loop runs in the Sandcastle. Your orchestrating code’s only job is to boot the Sandcastle, push your agent code, and start it. The agent then uses the local filesystem and/sandbox/files/library mount directly — no per-step round-trip — and makes model/tool calls out through the Sandcastle’s egress proxy.
Outbound network
Sandcastle egress flows through a forward proxy that records every outbound call (host, status, bytes, duration) to an egress ledger and enforces an allowlist — you can see this in the Network tab of any Sandcastle. For the agent-inside topology this matters:- The model endpoint your loop calls (e.g.
api.anthropic.com) must be permitted by the egress policy, or the call shows up asdeniedin the ledger. - In-cluster TextQL services are blocked from the Sandcastle except the sandbox proxy/query ports, so the agent reaches connectors and the Context Library through the provided mounts and the
/queryendpoint, not by calling internal services directly.
Persisting changes back to the Library (writeback)
Both topologies can read/sandbox/files/library, and both can write back to it. Edits an agent makes to that mount are diffed against a baseline snapshot (/sandbox/files/.internal/library.snapshot) and surfaced as a patch for review/approval before they land in canonical git — the same pipeline whether the edit comes from the in-product chat tool or the Sandcastle API.
Author a patch
open), unless an auto-approve rule
matches (approved, already live). See Create Library
Patch.How this maps to the Library backend
When context is enabled,/sandbox/files/library is materialized per session from your org’s canonical, git-versioned Context Library:
- On FSx ONTAP deployments, the worker mounts a writable FlexClone of the latest approved snapshot, pruned in-place to your
OWNERSpermissions — copy-on-write, so startup is fast and isolated per session. - On the default filestore backend, permitted contents are copied into the session tree.
.git / OWNERS metadata is stripped or locked, so a Sandcastle only ever sees the slice of org memory the caller is allowed to see.