Conversation
Implements sandbox-agent-managed hooks that work universally across all agents (Claude, Codex, OpenCode, Amp, Mock). Hooks are shell commands executed at specific lifecycle points in a session. ## Hook Types - on_session_start - Executed when a session is created - on_session_end - Executed when a session terminates - on_message_start - Executed before processing each message - on_message_end - Executed after each message is fully processed ## Features - Hooks are configured via the API when creating sessions - Environment variables provide context (SANDBOX_SESSION_ID, SANDBOX_AGENT, etc.) - Configurable timeout per hook - continue_on_failure option to control execution flow - Working directory support for hook execution ## API Changes - CreateSessionRequest now accepts optional 'hooks' and 'workingDir' fields - HooksConfig and HookDefinition schemas added to OpenAPI spec ## Testing - 8 unit tests for hook execution - 9 integration tests using mock agent with snapshot testing - Tests cover all lifecycle hooks, multiple hooks, failure handling, and env vars
|
🚅 Deployed to the sandbox-agent-pr-45 environment in sandbox-agent
|
Code ReviewFound 5 issues that need attention: CLAUDE.md Violations1. TypeScript SDK not updated The HTTP API was changed to add sandbox-agent/server/packages/sandbox-agent/src/router.rs Lines 3621 to 3628 in e84967f However, the TypeScript SDK was not updated in this PR. According to CLAUDE.md:
2. CLI not updated to expose hooks and working_dir parameters The HTTP API now accepts sandbox-agent/server/packages/sandbox-agent/src/main.rs Lines 205 to 223 in e84967f These are currently hardcoded to sandbox-agent/server/packages/sandbox-agent/src/main.rs Lines 494 to 497 in e84967f According to CLAUDE.md:
3. docs/cli.mdx not updated The CLI command structure was modified to include new According to CLAUDE.md:
Bugs4. Potential deadlock in stdout/stderr reading In sandbox-agent/server/packages/sandbox-agent/src/hooks.rs Lines 236 to 250 in e84967f This creates a classic pipe deadlock scenario:
Suggested fix: Use 5. Child process not killed on timeout (resource leak) In sandbox-agent/server/packages/sandbox-agent/src/hooks.rs Lines 318 to 337 in e84967f The problems:
Result: A command like Suggested fix: Store the child process in a way that allows cleanup, or use a different approach that can properly terminate timed-out processes. |
Summary
Adds universal hooks support to sandbox-agent. Hooks are managed by sandbox-agent itself (not agent-native hooks) and work across all supported agents.
Hook Types
on_session_start— After session creationon_session_end— When session terminateson_message_start— Before message is processedon_message_end— After message/response completesAPI Changes
Extended
CreateSessionRequestwith:hooks: Option<HooksConfig>working_dir: Option<String>HookDefinition
Environment Variables
Hooks receive:
SANDBOX_SESSION_IDSANDBOX_AGENTSANDBOX_AGENT_MODESANDBOX_HOOK_TYPESANDBOX_MESSAGE(for message hooks)Testing