marimo-zero / marimo_sandbox.py
Decree's picture
Fix: Remove --host flag for zeroclaw, fix Marimo duplicate imports
6f3820e
# /// script
# requires-python = ">=3.10"
# dependencies = ["marimo"]
# ///
import marimo
__generated_with = "0.17.6"
app = marimo.App()
@app.cell
def _():
import marimo as mo
import os
WORKSPACE = os.environ.get("WORKSPACE", "/app/workspace")
return WORKSPACE, mo, os
@app.cell
def _(mo):
mo.md("# πŸ¦€ Marimo Sandbox")
mo.md("Toggle this panel from Agent Zero chat UI")
mo.md("---")
return
@app.cell
def _(mo):
"""Code Editor Cell"""
mo.md("### πŸ’» Code Editor")
code_editor = mo.ui.code_editor(
language="python",
value="# Write your code here\nprint('Hello from Marimo Zero!')",
label=""
)
def run_code(code):
import sys
from io import StringIO
old_stdout = sys.stdout
sys.stdout = buf = StringIO()
try:
exec(code, {}, {})
output = buf.getvalue()
if output:
return mo.md(f"**Output:**\n```\n{output}\n```")
else:
return mo.md("βœ… Code executed (no output)")
except Exception as e:
return mo.md(f"❌ Error:\n```\n{str(e)}\n```")
finally:
sys.stdout = old_stdout
result = run_code(code_editor.value)
mo.vstack([
code_editor,
mo.ui.run_button(label="▢️ Run"),
result
])
return
@app.cell
def _(mo, WORKSPACE, os):
"""File Browser Cell"""
mo.md("### πŸ“ Workspace Files")
def list_files():
if not os.path.exists(WORKSPACE):
return mo.md("⚠️ Workspace not found")
files = os.listdir(WORKSPACE)
if not files:
return mo.md("πŸ“­ Empty workspace")
file_list = "\n".join([f"- πŸ“„ `{f}`" for f in sorted(files)])
return mo.md(file_list)
list_files()
return
@app.cell
def _(mo, WORKSPACE, os):
"""File Editor Cell"""
mo.md("### ✏️ File Editor")
filename = mo.ui.text(
label="Filename:",
value="example.md",
full_width=False
)
filepath = os.path.join(WORKSPACE, filename.value)
def read_file(name):
path = os.path.join(WORKSPACE, name)
if os.path.exists(path):
with open(path, 'r') as f:
return f.read()
return "# New file\n\nStart writing..."
content = mo.ui.text_area(
label="Content:",
value=read_file(filename.value),
full_width=True,
height=300
)
def save_file(name, text):
path = os.path.join(WORKSPACE, name)
with open(path, 'w') as f:
f.write(text)
return mo.md(f"βœ… Saved to `{path}`")
mo.vstack([
filename,
content,
mo.ui.run_button(label="πŸ’Ύ Save"),
save_file(filename.value, content.value)
])
return
@app.cell
def _(mo):
"""Terminal Output Cell"""
mo.md("### πŸ“Š Output")
mo.md("""
View execution results, plots, and outputs here.
**Tip:** Use `print()` in code cells to see output here.
""")
return
if __name__ == "__main__":
app.run()