Fallback workflow for document generation when code sandbox returns opaque errors
When execute_code_sandbox returns opaque or unhelpful errors during document/PDF generation, use run_shell with direct python -c execution as a reliable alternative. This pattern includes library availability checks and explicit error handling.
execute_code_sandbox fails with unclear error messages during document generationBefore attempting generation, verify required libraries are installed:
run_shell: python -c "import reportlab; print('reportlab OK')"
run_shell: python -c "import fpdf; print('fpdf OK')"
run_shell: python -c "import PyPDF2; print('PyPDF2 OK')"
If a library is missing, install it:
run_shell: pip install reportlab --quiet
Instead of execute_code_sandbox, use run_shell with python -c:
run_shell: python -c "
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas('output.pdf', pagesize=letter)
c.drawString(100, 750, 'Document Content')
c.save()
print('PDF generated successfully')
"
Wrap generation code with try/except and capture stderr:
run_shell: python -c "
import sys