fix(python): clarify run_script() reads from host, add run_guest_script()#249
fix(python): clarify run_script() reads from host, add run_guest_script()#249
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #235 by clarifying that run_script() reads from the host filesystem and adding a new run_guest_script() method to execute scripts that exist inside the VM. The change improves the API's clarity and provides the missing functionality users expected.
Changes:
- Updated
run_script()docstring to explicitly state it reads from the host filesystem and sends contents to the container - Added new
run_guest_script()method to execute Python scripts that exist inside the container - Added cross-reference documentation linking the two methods
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sdks/python/boxlite/codebox.py
Outdated
|
|
||
| Returns: | ||
| Execution output as a string | ||
| Execution stdout as a string |
There was a problem hiding this comment.
The docstring states "Execution stdout as a string" but the implementation returns stdout + stderr (via the run() method at line 89). This should be updated to "Execution output as a string (stdout + stderr)" to match the actual behavior and be consistent with the run() method's documentation at line 56.
| Execution stdout as a string | |
| Execution output as a string (stdout + stderr) |
sdks/python/boxlite/codebox.py
Outdated
| Execution stdout as a string | ||
| """ | ||
| result = await self.exec("/usr/local/bin/python", guest_script_path) | ||
| return result.stdout |
There was a problem hiding this comment.
The run_guest_script() method returns only stdout, which is inconsistent with run() and run_script() that both return stdout + stderr. This inconsistency could lead to unexpected behavior where stderr output (including error messages) is silently discarded. Consider changing line 102 to return result.stdout + result.stderr to maintain consistency across all execution methods.
| Execution stdout as a string | |
| """ | |
| result = await self.exec("/usr/local/bin/python", guest_script_path) | |
| return result.stdout | |
| Execution output as a string (stdout + stderr) | |
| """ | |
| result = await self.exec("/usr/local/bin/python", guest_script_path) | |
| return result.stdout + result.stderr |
sdks/python/boxlite/codebox.py
Outdated
| guest_script_path: Path to the script inside the container | ||
|
|
||
| Returns: | ||
| Execution stdout as a string |
There was a problem hiding this comment.
The docstring states "Execution stdout as a string" but for consistency with the run() and run_script() methods, this should document what is actually returned. Update the Returns section to match the actual implementation (currently stdout only, but should likely be stdout + stderr for consistency).
6815c26 to
bf2527d
Compare
…pt() run_script() reads the script from the host filesystem via open(), then sends the content to the VM. The name and docstring were misleading — users expected it to run a script inside the VM. Fix: - Update run_script() docstring to clearly state it reads from the host filesystem and point to run_guest_script() as alternative - Add run_guest_script() for running scripts already inside the VM Closes #235 Co-Authored-By: Claude Opus 4.6 <[email protected]>
bf2527d to
6008091
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| guest_script_path: Path to the script inside the container | ||
|
|
||
| Returns: | ||
| Execution output as a string (stdout + stderr) |
There was a problem hiding this comment.
Missing example in docstring. The run_guest_script method would benefit from a usage example similar to run_script, showing how to create a script inside the container and then execute it. This would help users understand the difference between run_script and run_guest_script more clearly.
| Execution output as a string (stdout + stderr) | |
| Execution output as a string (stdout + stderr) | |
| Example: | |
| Create a script inside the container and then execute it: | |
| >>> async with CodeBox() as cb: | |
| ... # Create the script inside the container filesystem | |
| ... await cb.exec( | |
| ... "sh", | |
| ... "-lc", | |
| ... "printf 'print(\\\"Hello from guest script!\\\")' > /tmp/guest_script.py", | |
| ... ) | |
| ... # Now run the script that lives inside the container | |
| ... result = await cb.run_guest_script("/tmp/guest_script.py") | |
| ... print(result) | |
| Hello from guest script! |
| guest_script_path: Path to the script inside the container | ||
|
|
||
| Returns: | ||
| Execution output as a string (stdout + stderr) |
There was a problem hiding this comment.
Missing example in docstring. The run_guest_script method would benefit from a usage example similar to run_script, showing how to create a script inside the container and then execute it. This would help users understand the difference between run_script and run_guest_script more clearly.
| Execution output as a string (stdout + stderr) | |
| Execution output as a string (stdout + stderr) | |
| Example: | |
| with SyncCodeBox() as box: | |
| # Create a script inside the container | |
| box.exec( | |
| "sh", | |
| "-lc", | |
| "cat << 'EOF' > /tmp/guest_script.py\n" | |
| "print('Hello from guest script!')\n" | |
| "EOF", | |
| ) | |
| # Run the script that now exists in the container filesystem | |
| result = box.run_guest_script("/tmp/guest_script.py") | |
| print(result) # Hello from guest script! |
|
Self-review after revision: This PR is now correct, with one documented dependency. The initial version had 3 bugs that have been fixed: Bug 1 — Wrong docstring. Bug 2 — Inconsistent run_guest_script() return. Bug 3 — SyncCodeBox not updated. Dependency on #248: This PR is self-consistent against |
|
this seems no need |
|
Closing — run_guest_script() interface is not needed. |
Summary
run_script()docstring: it reads from the host filesystem, not from inside the containerrun_guest_script()method for executing scripts that exist inside the VMSyncCodeBoxto maintain API parityCloses #235
Dependency
After PR #248 is merged (which changes
run()to return stdout only),run_guest_script()andSyncCodeBox.run_guest_script()should be updated to also return stdout only for consistency. Currently they returnstdout + stderrto match the currentrun()behavior.Test plan
run_script()still works with host-side scriptsrun_guest_script()works with container-side scripts🤖 Generated with Claude Code