Skip to content

feat(cli): add JSON output to exec - #1395

Draft
Whxuan0701 wants to merge 2 commits into
superradcompany:mainfrom
Whxuan0701:agent/exec-json
Draft

feat(cli): add JSON output to exec#1395
Whxuan0701 wants to merge 2 commits into
superradcompany:mainfrom
Whxuan0701:agent/exec-json

Conversation

@Whxuan0701

@Whxuan0701 Whxuan0701 commented Aug 18, 2026

Copy link
Copy Markdown

TL;DR

Add structured JSON output to msb exec so agents and host-side orchestrators can consume exit status and captured output without parsing terminal text.

Description

  • Add msb exec NAME --format json -- COMMAND for non-interactive execution.
  • Return exit_code, success, stdout, and stderr in one JSON object.
  • Preserve UTF-8 as text and encode arbitrary output bytes as Base64 with explicit encoding fields.
  • Keep the guest exit code as the msb process exit code.
  • Reject JSON output with --tty or --stream, and document the machine-readable contract.

Test Plan

  • cargo fmt --all -- --check
  • cargo test -p microsandbox-cli --lib in rust:1.97-bookworm with libcap-ng-dev (314 passed)
  • cargo clippy -p microsandbox-cli --lib -- -D warnings in the same Linux container

Real microVM execution was not run because the available host is Intel macOS, while this project's local libkrun runtime does not support that host configuration.

Expose captured stdout, stderr, and guest exit status as structured JSON
for reliable host-side agent orchestration. Preserve arbitrary output bytes
with explicit UTF-8 or Base64 encoding metadata.
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["msb exec --format json"] --> B{"Explicit or image-default command?"}
  B -->|Yes| C["Execute and capture output"]
  C --> D["Serialize JSON result"]
  B -->|No| E["Exit 0 before serialization"]
Loading

Fix all with Greploop Fix All in Codex Fix All in Claude Code

Prompt To Fix All With AI
### Issue 1
crates/cli/lib/commands/exec.rs:107-111
**JSON result skipped without command**

When `--format json` is used without an explicit command and the sandbox image has no default command, non-interactive resolution reaches the successful early-exit branch before serialization, causing the process to exit with status 0 while stdout contains no JSON result.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "feat(cli): add JSON output to exec" | Re-trigger Greptile

Comment thread crates/cli/lib/commands/exec.rs
Reject missing commands in JSON mode and explicitly flush structured output
before propagating the guest exit status.
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "fix(cli): preserve exec JSON output cont..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant