Features
AI Coding
Leverage AI to modify sandbox files with sandbox_code
Use the sandbox_code()
method to apply AI-assisted code changes in your sandbox environment.
The sandbox_code()
Method
Parameters
- prompt (
str
): Natural language instruction for the AI - editable_files (
List[str]
): List of absolute paths in the sandbox the AI may modify - readonly_files (
List[str]
, optional): List of absolute paths the AI can read but not modify
Return Value
The method returns a dictionary with:
success
(bool
): Whether meaningful changes were madediff
(str
): Diff of changes in unified formatstdout
/stderr
(optional): Outputs if code execution is part of diffcost
andcredits_remaining
: Cost information if authenticated
Basic Example
Multi-File Example
Real-World Scenario
Best Practices
- Use absolute paths starting with
/home/user/
- Provide context files in
readonly_files
to improve AI suggestions - Be specific in the prompt about function names, error handling, and patterns
- Combine related file changes into a single call for context consistency