mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-27 17:00:37 +00:00
* docs: turn README into an index and move reference detail to docs/guide The README had grown to 393 KB because every change appended its notes there. The text moves verbatim into 18 topic guides under docs/guide/; only headings are re-leveled and relative links re-pointed. The README keeps the introduction, a quick start and a guide index. Contributor test notes move to CONTRIBUTING.md. * docs: send user docs to topic guides and budget the root README The rule 'update README.md for user-facing changes' is what grew the README. Guidance now points to docs/guide/, and check_agent_guidance.py fails when the root README exceeds 16 KiB (AG003). * chore: remove unreferenced screenshots and finished plan notes pr-build/ holds two PR screenshots (3 MB) from #1986. plans/ holds the plan for the merged #4049. docs/SKILL_NAME_CONFLICT_FIX.md is a February change note. Nothing references them. * docs: route always-loaded AGENTS.md files to scoped guides * docs(agents): cut scoped guides to scope, verify, traps, decisions Each AGENTS.md keeps four kinds of content: the scope of the directory, the verification commands, traps a local test run does not show, and decisions the code cannot state. Values, field lists, function inventories, test names, issue numbers and history are deleted, because the code, the tests and git state them. Search and fetch providers share one community guide. Four guides with no remaining content are removed. The size check now allows 6 KiB per file (hard limit 8 KiB) and 24 KiB per chain (hard limit 32 KiB). * style: format frontend guide table and guidance test imports --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
4.5 KiB
4.5 KiB
Sandbox (deerflow/sandbox/)
The Sandbox and SandboxProvider interfaces, the local provider, the sandbox
tools (bash, ls, glob, grep, read_file, write_file, str_replace) and
the pieces every provider shares: identity, leases, environment policy and bounded
downloads. Remote providers live in deerflow/community/<provider>/ and have
their own guides.
Verify
cd backend
python -m pytest tests -q -k "sandbox or local_grep or env_policy"
make test-blocking-io # provider lookups run on the event loop
A change to shell quoting, encodings or path mapping also needs a run on native Windows. The portable string assertions do not replace it.
Paths
- The agent sees
/mnt/user-data/{workspace,uploads,outputs}and/mnt/skills. The provider's mount table is the only place that maps them to host paths. Tool code resolves/mnt/user-data/...only and leaves skills, ACP workspaces and custom mounts virtual, so that there is one source of truth per acquire. - A virtual parent that has no host directory (the default skills root) is searched through its mounts only. Falling back to the host parent would expose unrelated host files.
- Error messages translate host paths back to virtual paths at the sandbox boundary. The model must not see host paths.
- Both
localandlocal:<user>:<thread>are local sandbox IDs. Useis_local_sandbox().
Identity, leases and shutdown
- Sandbox identity is
(user_id, thread_id). Remote IDs come fromderive_sandbox_scope_token. Changing its output orphans every running container. A lookup miss acquires by user and thread, never by checkpoint ID. - Authorization comes first. Every sandbox-backed tool call passes the
sandbox:executegate before it reuses a persisted sandbox ID or acquires a new one. A restored ID is not proof of permission. - Two kinds of lease. The cross-instance ownership lease decides which Gateway
may reap a container. The process-local
SandboxLeaseManagercounts the users of one client (lead agent, subagents, Gateway requests, channel uploads). Release a container only when the local count is zero. get()andget_scoped()never block. They run on the event loop and read process memory only. Store and network calls belong in the acquire path.- Shutdown can be retried. A provider whose shutdown failed stays registered so that the next attempt can finish. Hosts that drain runs first (the Gateway lifespan) take shutdown ownership before any provider exists; providers created after that skip their own SIGTERM and SIGINT handlers.
- Cancellation. Signal the managed shell before you drain a cancelled command, and stop only the processes that belong to the lease owner.
Security
- Environment.
build_sandbox_env()removes inherited credential variables. Values fromsandbox.environmentand per-request secrets are added after the scrub. Route every new subprocess launch through it. - Network approval needs a human. Runs with no interactive responder (scheduled, webhook, autonomous, subagent) deny automatically. Never show an approval card that nobody can answer.
- Downloads are bounded while reading. Use
sandbox/download.py; the smaller of the caller limit and the provider limit applies. A size check after the read is too late. - Agent skill policy. A thread with an explicit Agent policy gets its own skills projection. Subagents reuse the lead's filesystem view and never rebuild it.
Tools
- Tool execution depends on operational arguments only. The
descriptionargument is a progress label and may be empty. - Local writes publish a new file revision atomically and keep symlink targets and file metadata. Check write access without truncating the file.
- Line endings are data. Full reads return the stored endings, and
str_replacematches the endings of the file. Remote providers split withsplit_file_lines, becausesplitlines()also splits on other Unicode separators. - A failed or incomplete directory traversal is an error. Returning a partial listing makes the model believe that files do not exist.
- Same-path write serialization is scoped to
(sandbox.id, path). Two isolated sandboxes use the same virtual paths and must not contend.
Adding a provider
Reuse the shared pieces: derive_sandbox_scope_token, AcquireSerializer,
WarmPoolLifecycleMixin and the ownership store in
aio_sandbox. Scoped command hooks default to
pass-through, so a provider without server-side sessions needs no change.