This repository was archived by the owner on Apr 21, 2026. It is now read-only.
fix: Switch code() to interactive stream-json mode and run CLI as non-root#4
Merged
Merged
Conversation
864b71f to
9130c22
Compare
…-root Two independent issues prevented code() from working: 1. One-shot mode (-p prompt) does not stream stdout through BoxLite's pipe-based exec. Interactive mode (--input-format stream-json) works correctly, streaming NDJSON responses in real-time. 2. Claude CLI v2.0.76 rejects --dangerously-skip-permissions when running as root, which is the default user in BoxLite VMs. Changes: - Rewrite code() to use interactive stdin/stdout protocol instead of one-shot -p flag. Sends prompt as NDJSON on stdin, reads streamed responses from stdout. - Add _setup_claude_user() to create non-root 'claude' user in VM during __aenter__(), with workspace permissions. - Add _build_claude_cmd() to wrap all CLI invocations with su -c "ENV=val claude --flags" claude. - Update _start_claude() (used by stream()) with same su -c wrapping. - Add debug logging throughout code() for diagnostics. - Add logging.basicConfig to all example files. - Fix test mocks: add stdin mock, proper NDJSON output, AsyncMock for runtime.create(). - Update templates, docs, and CI configuration.
9130c22 to
87d1642
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
code()from broken one-shot mode to interactive stream-json mode — one-shot (-p prompt) does not stream stdout through BoxLite's pipe-based exec; interactive mode sends prompt via stdin as NDJSON and streams responses correctly--dangerously-skip-permissionswhen running as root (the default in BoxLite VMs); now creates aclaudeuser and wraps all CLI calls withsu -ccode(), proper NDJSON mock output, andAsyncMockforruntime.create()Root Cause
Diagnosed via
test_oneshot_vs_interactive.pyrunning inside a real BoxLite VM:-p prompt)stream-json)Changes
src/claudebox/box.pycode()to interactive mode; add_setup_claude_user(),_build_claude_cmd(); update_start_claude()tests/conftest.pyAsyncMockforruntime.createexamples/*.pylogging.basicConfig()for visible debug outputTest plan
pytest tests/ -v)python examples/01_basic_usage.pywithCLAUDE_CODE_OAUTH_TOKENset — verify log output and successfulcode()completion