Build with Agents
Give an AI Agent its own identity, a sandbox it can't escape, safe writes and an undo for everything. The pattern, the rules to give it, and many Agents in one drive.
這一頁還沒有翻譯,所以先以英文顯示。
An Agent should be able to try things without anyone worrying about what it touches. Side Space gives it a member identity of its own, a zero-copy fork to work in, writes that fail instead of overwriting someone, and a history that can put anything back. You review what it changed and apply only what you keep.
What you work with
| You need | Side Space gives you |
|---|---|
| Know what the Agent did | An Agent member of its own. Its saves carry the Agent badge in history, activity and the journal |
| Keep it inside one place | A token limited to named drives and scopes. Other drives don't exist for it |
| A sandbox | A fork of a drive or one folder, made in a moment with no bytes copied |
| Review and keep part of it | fork changes, then fork apply for everything or only some paths, with a dry run first |
| Never lose a version | Every save is a version. Restore a file or rewind a folder, and both can be undone |
| No silent overwrites | If-Match (save only if the file is still at the version you read) and If-None-Match: * (create only if nothing is there). A stale write gets 412 |
| Small changes to big files | In-place edits send only the changed bytes |
| Talk to it in plain words | The MCP server with the same identity and limits |
The pattern
Four steps: fork, hand over a token, let it work, review and apply. These commands are run as you, an owner or admin of the workspace.
# 1. An identity for the Agent, and a sandbox of the folder it will work on
side agent create Claude
side fork create "Film A – try 2" --path /Ep01
side members --add Claude --role editor # it joins the workspace
# 2. A token that only reaches the sandbox
side token create claude-sandbox --agent Claude --scope files:write --drive "Film A – try 2"
# → ssp_… give this to the Agent as SIDESPACE_TOKEN
# 3. The Agent works in "Film A – try 2" (CLI, SDK, S3 or MCP). "Film A" doesn't exist for it.
# 4. Look at what it did and bring back what you keep
side fork changes "Film A – try 2"
side fork apply "Film A – try 2" --dry-run
side fork apply "Film A – try 2" /selects # only this folderTo throw the work away, don't apply it, and revoke the token with side token revoke. The original never changed.
An Agent's token that is limited to some drives may also fork them itself. Its forks are added to its drives, so it can open a fresh sandbox per task without asking you.
What the Agent's code looks like
Read, change, and save only if nobody saved in between. On a 412, read again and redo the change on the new content.
import { SideSpace, SideSpaceError } from "@sidespace/sdk";
const side = new SideSpace({ baseUrl: process.env.SIDESPACE_URL!, token: process.env.SIDESPACE_TOKEN! });
for (let attempt = 0; ; attempt++) {
const file = await side.node("/script.md");
const text = new TextDecoder().decode(await side.download("/script.md", { versionId: file.head_version_id! }));
const at = new TextEncoder().encode(text.slice(0, text.indexOf("NIGHT"))).length;
try {
await side.edit("/script.md", [{ at, delete: 5, text: "DAWN" }], { ifVersionId: file.head_version_id! });
break;
} catch (e) {
if (e instanceof SideSpaceError && e.code === "precondition_failed" && attempt < 3) continue;
throw e;
}
}from sidespace import SideSpace, SideSpaceError
side = SideSpace() # SIDESPACE_URL and SIDESPACE_TOKEN from the environment
for attempt in range(4):
head = side.node("/script.md")["head_version_id"]
text = side.download("/script.md", version_id=head)
at = text.index(b"NIGHT")
try:
side.edit("/script.md", [{"at": at, "delete": 5, "text": "DAWN"}], if_version_id=head)
break
except SideSpaceError as e:
if e.code != "precondition_failed" or attempt == 3:
raiseread -r NODE HEAD < <(curl -s -H "Authorization: Bearer $SIDESPACE_TOKEN" \
"$SIDESPACE_URL/v1/space/paths/script.md" | jq -r '"\(.id) \(.head_version_id)"')
curl -X POST -H "Authorization: Bearer $SIDESPACE_TOKEN" -H "Content-Type: application/json" \
-H "If-Match: \"$HEAD\"" "$SIDESPACE_URL/v1/space/nodes/$NODE/edits" \
-d '{"ops": [{"at": 14, "delete": 5, "text": "DAWN"}]}'
# 412 {"error": {"code": "precondition_failed", "details": {"current_version_id": "ver_…"}}} → read againOffsets are bytes, so count the UTF-8 bytes before the text you change, as above. Saving a whole file works the same way: upload takes ifVersionId (Python if_version_id), and ifNew (if_new) creates a file only if there's none.
Rules to give your Agent
Put these in your Agent's system prompt, AGENTS.md or CLAUDE.md. The server's /llms-full.txt ends with the same rules, so an Agent that reads it gets them too.
## Side Space
- Work only in the drive you were given. If you need a sandbox, fork it; never ask for wider access.
- Read a file's head_version_id before you change it and pass it as ifVersionId / If-Match.
On 412 precondition_failed, read the file again and redo your change. Never retry the same bytes.
- Create files with ifNew / If-None-Match: * so you never replace someone else's file.
- For a small change to a long file, edit in place (edit / edit_text) instead of saving all of it again.
- Put results about a file (tags, summaries, transcripts) in a sidecar, not in new files next to it.
- Saving never destroys, but ask before you delete, move many files, or change members and shares.
- Before rewinding a folder, run the rewind as a dry run and show the list.
- When you finish, list your changes (fork changes) and say what you changed and why.Many Agents, one drive
Several Agents can share a drive safely, because every write states what it expects to find.
Claim work by creating a marker that can only be created once. The first Agent wins; the others get 412 and move on.
try { await side.upload(`/claims/${clip}.json`, JSON.stringify({ by: "tagger-2" }), { ifNew: true }); // ours: process the clip } catch (e) { if (!(e instanceof SideSpaceError && e.code === "precondition_failed")) throw e; // someone else has it: take the next clip }Shared files like
notes.mdtake guarded edits.appendTextis already guarded by the version it read, so two Agents appending at once don't lose a line: one gets 412 and appends again.Over S3, the same rules are
IfNoneMatch="*"onput_objectand thex-sidespace-if-versionheader. See S3 tools.Who did what is in each version's author and in the journal, one Agent member per Agent.
Common mistakes
- One token for everything. Give each Agent its own member and a token limited to its drives and scopes. Revoking it then stops only that Agent.
- Working in the original. History lets you put things back, but a fork lets you not have to, and shows the whole result as one list.
- Saving without a version. A plain save is "last save wins". It notifies the person it replaced, but an Agent should check first.
- Rewriting a whole file to change a line. It's slower and turns a one-word change into a full new upload. Use an in-place edit.
- Retrying a 412 with the same bytes. The file changed. Read it again and redo the change on what's there now.
Docs for programs
Everything here can be read by code, on your own server's address:
| Address | What |
|---|---|
/llms.txt | A short guide for Agents: what a drive is, the main calls and where to look next |
/llms-full.txt | The same, plus every operation and the rules above, in plain text |
/v1/operations.json | Every operation as JSON, for tool builders |
/v1/openapi.yaml | The OpenAPI description |
/docs/llms.txt | A list of these guides, each with a Markdown address |
/docs/<page>.md | Any guide as Markdown, for example /docs/agents.md |
To use Side Space from Claude without writing code, see Use it in Claude.