Add --json flag for structured JSON event output to stderr#209
Open
hattori7243 wants to merge 1 commit intoanthropic-experimental:mainfrom
Open
Add --json flag for structured JSON event output to stderr#209hattori7243 wants to merge 1 commit intoanthropic-experimental:mainfrom
hattori7243 wants to merge 1 commit intoanthropic-experimental:mainfrom
Conversation
When enabled via --json, the CLI emits one JSON object per line to stderr for: - cli_error: when the CLI encounters errors (no command, signal, spawn failure, init error, fatal) - network_blocked: when a network request is denied (with host, port, reason, matching rule) - fs_violation: filesystem violations from the violation store (macOS log monitor) - sandbox_summary: on child process exit (exit code, duration, total blocks) This makes sandbox blocking events machine-readable for other tools that wrap the CLI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--jsonCLI flag that emits one JSON object per line to stderr for machine-readable sandbox event outputtypefield (cli_error,network_blocked,fs_violation,sandbox_summary) plus context-specific fields (host, port, reason, exitCode, duration, etc.)Motivation
Other languages/tools wrapping the
srtCLI need to parse sandbox events programmatically. Plain text stderr output is hard to parse reliably. Structured JSON Lines output enables automated processing of network blocks, filesystem violations, and exit summaries.Usage
Changed files
src/utils/structured-logger.tssrc/cli.ts--jsonflag, emit events at error/exit pathssrc/sandbox/sandbox-manager.tsnetwork_blockedevents fromfilterNetworkRequest()No changes to proxy servers, sandbox builders, or existing function signatures. All logging is no-op when
--jsonis not set.Test plan
srt --json -c "echo hello"producessandbox_summaryevent on stderrsrt --json -c "curl http://denied.example"producesnetwork_blocked+sandbox_summaryeventssrt -c "echo hello"(no--json) behaves identically to before