Code Execution
Code execution lets you run Python scripts that call MonoClaw tools programmatically. This is powerful for collapsing multi-step workflows into a single turn.
When to use code execution
- Batch operations — Process multiple files at once
- Complex logic — Calculations, data transformations
- API orchestration — Chain multiple tool calls with custom logic
- Automation — Scripts that run periodically
Basic usage
In chat, use the code block with python:
```python
# Mona will execute this
import os
files = os.listdir("src/")
print(f"Found {len(files)} files")
for f in files:
print(f" - {f}")
```
Accessing tools
Scripts have access to Mona's tools via the tools object:
# Read a file
content = tools.file_read("README.md")
# Run a command
result = tools.terminal("git log --oneline -5")
# Search the web
results = tools.web_search("MonoClaw AI secretary")
Return values
Scripts can return structured data:
files = os.listdir("src/")
{
"count": len(files),
"files": files,
"largest": max(files, key=lambda f: os.path.getsize(f"src/{f}"))
}
Mona receives this data and can use it in her response.
Error handling
Script errors are caught and reported:
try:
result = tools.terminal(" risky_command ")
except Exception as e:
print(f"Error: {e}")
File system access
Scripts run with access to:
- The current working directory
/tmp/for temporary files- Read access to mounted volumes (Docker backend)
Security
- Scripts run in the same sandbox as terminal commands
- Dangerous operations require approval (if approval mode is enabled)
- Network access depends on the backend configuration
- File system access is scoped to the working directory
Best practices
- Keep scripts focused — One task per script
- Handle errors — Use try/except for robustness
- Return structured data — Makes it easier for Mona to use results
- Don't hardcode secrets — Use environment variables
- Clean up temp files — Delete
/tmp/files when done
Comparison with skills
| Code Execution | Skills | |
|---|---|---|
| Use case | One-off scripts | Reusable workflows |
| Persistence | Per-turn | Permanent |
| Complexity | Simple to moderate | Complex, multi-step |
| Sharing | Copy-paste | Installable package |