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. Declare them once, and each harness writes them in its own native format."
6---
7
8Provisioning writes tokens, skills, MCP servers, and house rules into the files each CLI expects.
9
10Provisioning lets you declare all of it once, on [`defineWorkspace()`](./workspace). At bootstrap, each harness adapter writes it in the format its CLI reads.
11
12## Provision a workspace
13
141. Wrap your secrets with `createSecrets`. You get opaque refs, not strings.
152. List your skills, plugins, and instructions on `defineWorkspace`.
163. Pass the workspace to `defineSandbox`, and use the sandbox as usual.
17
18```ts
19import {
20 bearer,
21 createSecrets,
22 defineSandbox,
23 defineWorkspace,
24 fileSkill,
25 gitSkill,
26 githubRepo,
27 mcpSkill,
28} from '@tanstack/ai-sandbox'
29import { dockerSandbox } from '@tanstack/ai-sandbox-docker'
30
31const secrets = createSecrets({
32 ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? '',
33 GH: process.env.GH_TOKEN ?? '',
34 SENTRY: process.env.SENTRY_TOKEN ?? '',
35})
36
37export const repoSandbox = defineSandbox({
38 id: 'repo-agent',
39 provider: dockerSandbox({ image: 'node:22' }),
40 workspace: defineWorkspace({
41 source: githubRepo({ repo: 'owner/repo', ref: 'main' }),
42 // This example uses Claude Code. Install the CLI for your harness.
43 setup: [
44 'npm install -g @anthropic-ai/claude-code --include=optional && claude --version',
45 ],
46 secrets,
47 skills: [
48 // A public skill repo.
49 gitSkill({ repo: 'owner/tanstack-skills' }),
50 // A private skill repo. The token is used only for the clone.
51 gitSkill({ repo: 'owner/private-skills', secret: secrets.GH }),
52 // A third-party MCP server, with a bearer token header.
53 mcpSkill('sentry', {
54 url: 'https://mcp.example.com',
55 headers: { Authorization: bearer(secrets.SENTRY) },
56 }),
57 // Any file you want in the workspace.
58 fileSkill({ path: '.agent-hints.md', content: '# Hints\nPrefer pnpm.' }),
59 ],
60 plugins: ['@anthropic/plugin-foo'],
61 instructions: 'Always run `pnpm test` before proposing a change.',
62 }),
63})
64```
65
66Start a run with this sandbox and `claudeCodeText`. The agent can use the skills and the MCP server, and it reads your instructions from `AGENTS.md`.
67
68## How it works
69
70- **Secrets** stay as refs everywhere in your config. The real values are resolved only into the live sandbox env, at create, resume, and snapshot restore. They are never written to snapshots, the sandbox store, or the event log.
71- **Skills, MCP servers, and plugins** are written by the harness adapter at bootstrap, each in its CLI's native place. See [Per-harness projection](#per-harness-projection).
72- **Instructions** go to `AGENTS.md` at the workspace root. `CLAUDE.md` and `GEMINI.md` point to it.
73- **A CLI that lacks a concept** warns and skips that entry. It does not throw. So one definition works with every harness, and each agent takes the parts it understands.
74
75To limit what the agent is **allowed** to do (which commands run, which ask, which are denied), use [Policy](./policy), not instructions.
76
77## Advanced
78
79### Why secret values never leak
80
81`createSecrets` keeps the real strings in a **non-enumerable, symbol-keyed registry** on the object it returns. Each property you read (`secrets.GH`) is a `SecretRef` token, not the string. So:
82
83- `Object.keys(secrets)`, spreads, and `JSON.stringify(secrets)` never show the values.
84- The workspace definition is safe to hash, store, and replay for resume, with no credential in it.
85
86`secrets` is [declared on the workspace](./workspace). The harness adapters write secret-bearing MCP config again on every run, with fresh values. So a snapshot never serves a stale or rotated secret.
87
88### Where a `SecretRef` goes
89
90Pass a ref straight to any field that takes one. For `gitSkill`, pass `secret`. The token is resolved only when the repo is cloned.
91
92In MCP headers, use a ref as is, or wrap it with `bearer(ref)` to get `Bearer <value>`:
93
94```ts
95import { bearer, createSecrets, mcpSkill } from '@tanstack/ai-sandbox'
96
97const secrets = createSecrets({
98 GH: process.env.GH_TOKEN ?? '',
99 SENTRY: process.env.SENTRY_TOKEN ?? '',
100})
101
102export const sentry = mcpSkill('sentry', {
103 url: 'https://mcp.example.com',
104 headers: {
105 Authorization: bearer(secrets.SENTRY), // "Bearer <value>"
106 'X-Token': secrets.GH, // the raw token value
107 },
108})
109```
110
111### Skill builders
112
113| Builder | What it provisions |
114| --- | --- |
115| `gitSkill` | A skill repo cloned into the workspace, with optional `secret` and clone path. |
116| `mcpSkill` | A third-party MCP server, with `url` and `headers`. |
117| `fileSkill` | Any file written into the workspace. |
118| `agentSkill` | A public skill by bare name. Every bundled harness warns and skips it, so use `gitSkill` instead. |
119
120These MCP servers are third-party services. To give the agent your **own app's** tools (a `chat()` server tool whose `execute()` runs on your host), use [Tools](./tools).
121
122### `gitSkill` clone path
123
124`into` sets where the repo is cloned. It is an absolute path inside the sandbox. The default is `.tanstack-skills/<repo-basename>` under the workspace root. Bootstrap creates the parent directory before the clone.
125
126A path that starts with `/workspace` uses the portable workspace root, and the provider maps it to its real workdir. Keep `/workspace/...` unless you must pin a provider-specific path.
127
128```ts
129import {
130 createSecrets,
131 defineWorkspace,
132 gitSkill,
133 githubRepo,
134} from '@tanstack/ai-sandbox'
135
136const secrets = createSecrets({ GH: process.env.GH_TOKEN ?? '' })
137
138export const workspace = defineWorkspace({
139 source: githubRepo({ repo: 'owner/repo' }),
140 secrets,
141 skills: [
142 gitSkill({
143 repo: 'owner/private-skills',
144 secret: secrets.GH,
145 into: '/workspace/.skills/private',
146 }),
147 ],
148})
149```
150
151### Per-harness projection
152
153| Harness | MCP servers | `gitSkill` repos | `plugins` |
154| --- | --- | --- | --- |
155| Claude Code | `.mcp.json` | `.claude/skills/<name>` | `claude plugin install <name> --scope project` |
156| Codex | `.codex/config.toml` | `.codex/skills/<name>` | Warns and skips. |
157| Grok Build | `.grok/config.toml` | `.grok/skills/<name>` | Warns and skips. |
158| OpenCode | `opencode.json` | Warns and skips (cloned, not linked). | Warns and skips. |
159
160For a linked skill repo, the projector looks for folders that hold a `SKILL.md`:
161
162- A nested pack (`skills/foo/SKILL.md`) is linked under the name `foo`.
163- A flat clone with `SKILL.md` at its root uses the clone name.
164
165Links are symlinks. If `ln -s` fails, the projector copies the folder. You never write the links yourself.
166
167### `AGENTS.md` and its links
168
169Bootstrap writes `instructions` to `AGENTS.md` at the workspace root. It then creates `CLAUDE.md` and `GEMINI.md` as symlinks to it. If the sandbox cannot make symlinks, they are copies. Either way, every supported CLI reads the instructions with no extra config.