Open History to see the last commit
1---
2title: Provisioning (Advanced)
3id: provisioning
4order: 5
5description: "Give the in-sandbox agent secrets, skill repos, MCP servers, plugins, and instructions with one portable definition that each harness projects into its own native format."
6---
7
8Provisioning is how you hand the in-sandbox agent everything beyond the working
9tree: typed secrets, skill repos, MCP servers, plugins, and a universal
10instruction file. You declare it all on [`defineWorkspace()`](./workspace), and
11each harness adapter projects it into its own native format at bootstrap, so
12the same definition works whether the agent is Grok Build, Claude Code, Codex, or OpenCode.
13
14```ts
15import {
16 bearer,
17 createSecrets,
18 defineWorkspace,
19 fileSkill,
20 gitSkill,
21 githubRepo,
22 mcpSkill,
23} from '@tanstack/ai-sandbox'
24
25const secrets = createSecrets({
26 GH: process.env.GH_TOKEN ?? '',
27 SENTRY: process.env.SENTRY_TOKEN ?? '',
28})
29
30defineWorkspace({
31 source: githubRepo({ repo: 'owner/repo', ref: 'main' }),
32 secrets,
33 skills: [
34 gitSkill({ repo: 'owner/tanstack-skills' }),
35 gitSkill({ repo: 'owner/private-skills', secret: secrets.GH }),
36 mcpSkill('my-mcp', {
37 url: 'https://mcp.example.com',
38 headers: { Authorization: bearer(secrets.SENTRY) },
39 }),
40 fileSkill({ path: '.agent-hints.md', content: '# Hints\nPrefer pnpm.' }),
41 ],
42 plugins: ['@anthropic/plugin-foo'],
43 instructions: 'Always run `pnpm test` before proposing a change.',
44})
45```
46
47## Type-safe secrets
48
49`createSecrets` turns plain environment values into opaque `SecretRef` tokens.
50You pass the refs around your config; the underlying strings stay out of every
51serializable surface.
52
53```ts
54import { createSecrets, defineWorkspace, githubRepo } from '@tanstack/ai-sandbox'
55
56const secrets = createSecrets({
57 GH: process.env.GH_TOKEN ?? '',
58 SENTRY: process.env.SENTRY_TOKEN ?? '',
59})
60
61defineWorkspace({
62 source: githubRepo({ repo: 'owner/repo', ref: 'main' }),
63 secrets,
64})
65```
66
67`secrets` is [declared on the workspace](./workspace). At create, resume, and
68snapshot restore, the sandbox layer resolves them onto the live handle env.
69Providers never write those values into snapshots, the sandbox store, or the
70event log.
71
72### Why the values never leak
73
74The real strings are held in a **non-enumerable, symbol-keyed registry** on the
75object `createSecrets` returns. Each property you access (`secrets.GH`) is a
76`SecretRef` token, not the string. Because the registry is symbol-keyed and
77non-enumerable:
78
79- `Object.keys(secrets)`, spreads, and `JSON.stringify(secrets)` never expose
80 the values.
81- The values are **never written to snapshots, the sandbox store, or the event
82 log**. They are resolved only when the live sandbox env is built.
83
84This is what makes the workspace definition safe to hash, persist, and replay
85for resume bookkeeping without ever persisting a credential.
86
87### Passing a secret where a `SecretRef` is accepted
88
89Hand a ref directly to any field that takes one. The clearest example is
90`gitSkill` auth: pass `secret: secrets.GH` and the token is resolved only when
91the repo is cloned:
92
93```ts
94import { createSecrets, defineWorkspace, gitSkill, githubRepo } from '@tanstack/ai-sandbox'
95
96const secrets = createSecrets({ GH: process.env.GH_TOKEN ?? '' })
97
98defineWorkspace({
99 source: githubRepo({ repo: 'owner/repo' }),
100 secrets,
101 skills: [gitSkill({ repo: 'owner/private-skills', secret: secrets.GH })],
102})
103```
104
105### `bearer(ref)` for header values
106
107In MCP header values you can use a ref directly, or wrap it with `bearer(ref)`
108to produce a `Bearer <value>` string at resolution time:
109
110```ts
111import { bearer, createSecrets, mcpSkill } from '@tanstack/ai-sandbox'
112
113const secrets = createSecrets({
114 GH: process.env.GH_TOKEN ?? '',
115 SENTRY: process.env.SENTRY_TOKEN ?? '',
116})
117
118mcpSkill('my-mcp', {
119 url: 'https://mcp.example.com',
120 headers: {
121 Authorization: bearer(secrets.SENTRY), // resolves to "Bearer <value>"
122 'X-Token': secrets.GH, // resolves to the raw token value
123 },
124})
125```
126
127## Skills, plugins, and MCP servers
128
129`skills` is an array of skill values that provision capabilities into the
130agent's environment. There are four builders, each describing a different kind
131of capability:
132
133| Builder | What it provisions |
134| ------------ | ---------------------------------------------------------------------------------- |
135| `agentSkill` | A named public skill (portable placeholder; Claude Code warns and skips it, so use `gitSkill` instead). |
136| `gitSkill` | A skill repo cloned into the workspace, with optional auth and clone path. |
137| `mcpSkill` | A third-party MCP server, with URL and headers. |
138| `fileSkill` | An arbitrary file written into the workspace. |
139
140```ts
141import {
142 bearer,
143 createSecrets,
144 defineWorkspace,
145 fileSkill,
146 gitSkill,
147 githubRepo,
148 mcpSkill,
149} from '@tanstack/ai-sandbox'
150
151const secrets = createSecrets({
152 GH: process.env.GH_TOKEN ?? '',
153 SENTRY: process.env.SENTRY_TOKEN ?? '',
154})
155
156defineWorkspace({
157 source: githubRepo({ repo: 'owner/repo' }),
158 secrets,
159 skills: [
160 // Clone a public skill repo (preferred over agentSkill on Claude Code).
161 gitSkill({ repo: 'owner/tanstack-skills' }),
162 // Clone a private skill repo; `secret` is resolved from the secrets registry.
163 gitSkill({ repo: 'owner/private-skills', secret: secrets.GH }),
164 // Wire an MCP server with a resolved bearer token in the Authorization header.
165 mcpSkill('my-mcp', {
166 url: 'https://mcp.example.com',
167 headers: { Authorization: bearer(secrets.SENTRY) },
168 }),
169 // Write an arbitrary file into the workspace.
170 fileSkill({ path: '.agent-hints.md', content: '# Hints\nPrefer pnpm.' }),
171 ],
172 plugins: ['@anthropic/plugin-foo'],
173})
174```
175
176### `gitSkill` clone path
177
178`gitSkill` takes an optional `into` field, an **absolute path inside the
179sandbox**, controlling where the repo is cloned. It defaults to
180`.tanstack-skills/<repo-basename>`. Bootstrap creates the parent directory
181before the clone.
182
183Paths that start with `/workspace` use the portable workspace root. The
184provider maps that root onto its real workdir. Keep `/workspace/...` in
185`into` unless you have a reason to pin a provider-specific path.
186
187```ts
188import { createSecrets, defineWorkspace, gitSkill, githubRepo } from '@tanstack/ai-sandbox'
189
190const secrets = createSecrets({ GH: process.env.GH_TOKEN ?? '' })
191
192defineWorkspace({
193 source: githubRepo({ repo: 'owner/repo' }),
194 secrets,
195 skills: [
196 gitSkill({
197 repo: 'owner/private-skills',
198 secret: secrets.GH,
199 into: '/workspace/.skills/private',
200 }),
201 ],
202})
203```
204
205### Per-harness projection
206
207At bootstrap each harness projector maps these values into its CLI's native
208format:
209
210| Harness | MCP servers projected to |
211| ----------- | ------------------------ |
212| Claude Code | `.mcp.json` |
213| Codex | `.codex/config.toml` |
214| OpenCode | `opencode.json` |
215
216Each projector walks the cloned repo for folders that contain `SKILL.md`. A
217nested pack (`skills/foo/SKILL.md`) is linked under the skill name `foo`. A
218flat clone with `SKILL.md` at the root uses the clone name. You do not write
219`ln -s` by hand.
220
221A concept a given CLI lacks (for example, `plugins` on Codex) **emits a
222warning and is silently skipped** rather than throwing. The same applies to
223`agentSkill` on Claude Code: there is no reliable primitive to install a public
224skill by bare name, so the projector warns and skips it. Prefer `gitSkill` (or a
225`plugins` entry) when you need that skill on Claude Code. That keeps one
226portable definition usable across harnesses: you declare everything once, and
227each agent takes the parts it understands.
228
229> These MCP servers are third-party services you point the agent at. Bridging
230> your **own app's host tools** into the agent (a `chat()` server tool whose
231> `execute()` runs back on the host) is a different mechanism, see
232> [Tools](./tools).
233
234## `AGENTS.md` and per-harness symlinks
235
236`instructions` is a string written to `AGENTS.md` at the workspace root during
237bootstrap. Harness-specific counterparts (`CLAUDE.md`, `GEMINI.md`) are
238created as **symlinks** to it; if the sandbox process layer cannot symlink, they
239are written as copies instead. Either way the instruction content is read
240natively by every supported CLI without extra config.
241
242```ts
243import { defineWorkspace, githubRepo } from '@tanstack/ai-sandbox'
244
245defineWorkspace({
246 source: githubRepo({ repo: 'owner/repo' }),
247 instructions: 'Always run `pnpm test` before proposing a change.',
248})
249```
250
251> Use `instructions` for guidance you want the agent to always follow. To
252> constrain what it is *allowed* to do, which commands and capabilities are
253> allowed, asked about, or denied, reach for [Policy](./policy) instead.