All Products
Search
Document Center

Function Compute:Charts and Visualizations

Last Updated:Sep 16, 2026

FC Agent Sandbox Code Interpreter currently supports only the file-based fallback path for charts: generate chart files inside the sandbox, and then retrieve them through Filesystem. Do not rely on execution.results[].png or execution.results[].chart as the formal integration path.

Generate image files

When you use Matplotlib to generate a chart, save the image to a fixed path inside the sandbox:

sandbox.run_code("""import matplotlib.pyplot as plt; plt.plot([1, 2, 3], [1, 4, 9]);plt.savefig("/tmp/chart.png")""")

TypeScript example:

await sandbox.runCode(`import matplotlib.pyplot as plt; plt.plot([1, 2, 3], [1, 4, 9]); plt.savefig("/tmp/chart.png")`);

Then read the file contents:

content = sandbox.files.read("/tmp/chart.png", format="bytes")

TypeScript example:

const content = await sandbox.files.read("/tmp/chart.png", { format: "bytes" });

You can also hand the image to a browser or downstream system through an upload or download URL:

download_url = sandbox.download_url("/tmp/chart.png")

TypeScript example:

const downloadUrl = await sandbox.downloadUrl("/tmp/chart.png");

Generate multiple charts

Use stable filenames for multiple charts so they do not overwrite each other:

sandbox.run_code("""import matplotlib.pyplot as plt; plt.figure(); plt.plot([1, 2, 3]); plt.savefig("/tmp/chart-1.png"); plt.figure(); plt.bar(["A", "B"], [10, 20]); plt.savefig("/tmp/chart-2.png")""")

TypeScript example:

await sandbox.runCode(`import matplotlib.pyplot as plt; plt.figure(); plt.plot([1, 2, 3]); plt.savefig("/tmp/chart-1.png"); plt.figure(); plt.bar(["A", "B"], [10, 20]); plt.savefig("/tmp/chart-2.png")`);

Then read or download /tmp/chart-1.png and /tmp/chart-2.png separately.

Recommendations

  • When prompting AI to generate code, require plt.savefig() instead of plt.show().

  • Define an output directory and file naming convention, such as /tmp/chart.png or /tmp/charts/chart-1.png.

  • If you need long-term retention, write the images to OSS, a database, or application file storage.

  • For user-visible images, validate the file size and MIME type on the business side.