code_execute

Run JavaScript, Python, or Bash in a sandboxed Docker container. No network access.

File I/O Contract - "sandbox = your project"

Pre-installed Runtimes

CLI Tools (prefer one-liners over scripts)

Discovering tools

If unsure whether a tool or package is available, probe before using it - the sandbox has no network, so a fast check is cheaper than a failed run:

Worked Examples

1. FFmpeg - transcode MP4 → WebM

input_files: ["videos/clip.mp4"]
language: bash
code: ffmpeg -y -i videos/clip.mp4 -c:v libvpx-vp9 -b:v 1M -c:a libopus videos/clip.webm

Returns: project gains videos/clip.webm. The .mp4 is unchanged, so it is not re-written.

2. FFmpeg - extract 10 frames from a video

input_files: ["videos/clip.mp4"]
language: bash
code: |
  mkdir -p frames
  ffmpeg -y -i videos/clip.mp4 -vf "fps=10/$(ffprobe -v error -show_entries format=duration -of csv=p=0 videos/clip.mp4)" frames/frame_%03d.jpg

Returns: frames/frame_001.jpgframes/frame_010.jpg.

3. ImageMagick - resize + convert format

input_files: ["images/photo.jpg"]
language: bash
code: |
  mkdir -p thumbnails
  convert images/photo.jpg -resize 400x400 -quality 85 thumbnails/photo.webp

Returns: thumbnails/photo.webp.

4. Python pandas - filter/aggregate a CSV

input_files: ["data/sales.csv"]
language: python
code: |
  import pandas as pd
  df = pd.read_csv('data/sales.csv')
  q4 = df[df['quarter'] == 'Q4'].groupby('region')['amount'].sum().reset_index()
  q4.to_csv('data/sales_q4.csv', index=False)
  print(q4.to_string(index=False))

Returns: data/sales_q4.csv plus a printed preview on stdout.

5. Python matplotlib - chart a JSON metric series → PNG

input_files: ["data/metrics.json"]
language: python
code: |
  import json, os
  import matplotlib
  matplotlib.use('Agg')
  import matplotlib.pyplot as plt
  d = json.load(open('data/metrics.json'))
  os.makedirs('charts', exist_ok=True)
  plt.plot(d['labels'], d['values'])
  plt.xticks(rotation=45); plt.tight_layout()
  plt.savefig('charts/metrics.png', dpi=120)

Returns: charts/metrics.png (inline in the reply).

6. Bash + poppler - PDF → plain text

input_files: ["docs/manual.pdf"]
language: bash
code: |
  mkdir -p docs
  pdftotext -layout docs/manual.pdf docs/manual.txt
  wc -l docs/manual.txt

Returns: docs/manual.txt plus the line count on stdout.

Audio/Music Generation - use dedicated tools

Do NOT use code_execute with sox/ffmpeg to generate music or sound effects. Use:

These produce higher-quality results and handle file saving automatically.