Skip to main content
A coding agent with session-scoped sandbox tools. Two separate invoke() calls share the same sessionId, so the second agent run can see files created by the first. The Docker container persists between runs and is cleaned up automatically when idle.

Create session-scoped sandbox tools

The key difference from Sandbox Tools is scope: 'session'. This tells the SandboxManager to reuse the same Docker container across multiple invocations that share the same sessionId.

Define the agent

Run multiple invocations with a shared session

Pass the same sessionId to multiple invoke() calls. Each run streams events and waits for the agent to complete before starting the next. The second run sees files created by the first.

How it works

  1. sandboxTools({ scope: 'session' }) creates tools that look up or create a container keyed by sessionId
  2. The first invoke() creates a new Docker container and runs the agent inside it
  3. The second invoke() with the same sessionId reuses the existing container — files from Run 1 are still on disk
  4. The container is cleaned up automatically after an idle timeout

Comparison with default sandbox

Run it

Docker must be installed and running. The container image (node:20-slim) will be pulled automatically on first run.
Open http://localhost:5173 to view your agents and workflows, run them from the UI, and see execution traces. Python example on GitHub | TypeScript example on GitHub