.agents/references/sandbox-runtime-boundary.md
Use this reference for changes to sandbox session ownership, SandboxAgent preparation, manifests, capabilities, host-path materialization, snapshots, resume state, agent transitions, or cleanup.
The outer Runner owns agent turns, approvals, handoffs, tracing, session history, and RunState. A sandbox session owns the execution environment, workspace, processes, mounts, and provider-specific connection state. Do not move one layer's lifecycle into the other without defining resume and cleanup behavior for both.
SandboxRunConfig.session is caller-owned. The runner may configure and use it but must not delete or fully tear it down.SandboxRunConfig.client is runner-owned. Cleanup runs pre-stop hooks, persists snapshot-backed workspace state, stops and shuts down the session, deletes provider resources when required, and closes dependencies.SandboxAgent concurrency guards even when persistence or provider cleanup fails.SandboxAgent instance cannot be reused concurrently across runs because prepared capability tools and session state are bound to one live run. Clone or construct separate agents for concurrent work.Resolve the session source in this order: injected live session, resumable sandbox state carried by RunState, explicit SandboxRunConfig.session_state, then a newly created session. Manifest and snapshot inputs seed only a fresh session; they do not overwrite an injected or resumed workspace.
RunState sandbox data and explicit session_state represent provider connection or session state used to reconnect to existing work.SandboxAgent. Dynamic instructions and hooks should observe the public agent rather than an internal clone with implementation-only state.Agent.as_tool() run owns its own nested runner and sandbox lifecycle.LocalFile and LocalDir sources are host-side inputs. Resolve them against a trusted base directory, require explicit application-controlled extra_path_grants outside that base, and reject untrusted manifests that try to authorize their own host access.persist_workspace() include the workspace root, not arbitrary granted paths.Remote mounts should default to one narrow lifecycle: declare them during sandbox creation, keep their contents outside workspace persistence, and unmount them during close. When tar persistence or hydration requires detaching a mount, restore it immediately afterward. Mount credentials must remain trusted live configuration and must not be reconstructed from serialized session state.
Treat dynamic mount mutation, native-snapshot-backed mounts, and resumable mounts as opt-in provider capabilities rather than default requirements. If a privileged mount transition becomes ambiguous, stop the sandbox instead of adding reconciliation or recovery state. Do not add credential resolvers, refresh loops, persisted mount registries, or dynamic mount APIs unless the provider exposes a trusted primitive that makes the lifecycle transition unambiguous and the change is supported by focused provider evidence.
Provider adapters may deliberately support a narrower lifecycle. Document that boundary next to the adapter state that enforces it so future maintainers do not mistake an intentional exclusion for an unfinished feature. The Vercel S3 adapter follows the create-time-only form of this policy: its trusted mount configuration is live-session-only, sessions containing mounts cannot resume, and mount topology cannot change after creation.
Runner path so agent preparation, capability binding, persistence, and cleanup run together.docs/sandbox/guide.mddocs/sandbox/clients.mdsrc/agents/sandbox/runtime.pysrc/agents/sandbox/runtime_session_manager.pysrc/agents/sandbox/runtime_agent_preparation.pysrc/agents/sandbox/manifest.pysrc/agents/sandbox/materialization.pysrc/agents/sandbox/workspace_paths.pysrc/agents/sandbox/session/archive_extraction.pysrc/agents/extensions/sandbox/vercel/mounts.pysrc/agents/extensions/sandbox/vercel/sandbox.pytests/sandbox/test_runtime.pytests/sandbox/test_runtime_agent_preparation.pytests/sandbox/test_session_state_roundtrip.pytests/sandbox/test_materialization.pytests/sandbox/test_extract.py