AGENT SKILL

code-execution

Enabling Gemini's native sandboxed Python runtime, capturing code outputs, and mathematical/scientific executions.

License 许可
MIT
最近更新
2026-06-05
Stars
★ 2
Forks
0

01 前言 Front Matter

name
code-execution
license
MIT license
metadata
{ "skill-author": "Lord1Egypt" }
description
Enabling Gemini's native sandboxed Python runtime, capturing code outputs, and mathematical/scientific executions.
allowed-tools
Read Write Edit Bash

03 SKILL.md 正文

Gemini Code Execution Skill

Overview

This skill outlines how to enable Gemini's native, sandboxed Python Code Execution environment. When activated, Gemini can write Python code, execute it in an isolated sandbox during the generation process, inspect the printed outputs, and use the results to build its final answer.


When to Use This Skill

  • Complex mathematical equations or calculations.
  • Data analysis on provided charts or tables (e.g. calculating standard deviations, regressions).
  • Algorithms, code generation testing, and logic verifications.

Quick Start (with runnable code examples)

from google import genai

# Initialize the Gemini GenAI Client
client = genai.Client()

def run_scientific_computation(prompt: str):
    print(f"Sending prompt to Gemini with Native Python Execution: '{prompt}'...")
    
    # Configure the generate_content call with code_execution tool
    response = client.models.generate_content(
        model='gemini-2.5-flash',
        contents=prompt,
        config=dict(
            # Enable native code execution environment
            tools=[{'code_execution': {}}]
        )
    )
    
    print("\n--- Final Text Output ---")
    print(response.text)
    
    # Inspect the code that Gemini wrote and executed in the background
    candidate = response.candidates[0]
    parts = candidate.content.parts
    
    print("\n--- Background Code Executions ---")
    for part in parts:
        if part.function_call and part.function_call.name == "_exec_code":
            print("\n>>> Code Written by Gemini:")
            print(part.function_call.args.get("code"))
        elif part.function_response and part.function_response.name == "_exec_code":
            print("\n<<< Sandbox Output Result:")
            print(part.function_response.response.get("result"))

if __name__ == "__main__":
    query = (
        "Find the sum of all prime numbers between 1 and 1000. "
        "Write a Python script to calculate this, execute it, and give me the result."
    )
    run_scientific_computation(query)

Advanced Usage

Sandbox Limitations

The code execution environment is a locked-down, transient sandbox:

  • No Internet Access: The code inside the sandbox cannot query outside network APIs.
  • Limited Libraries: Major preloaded packages include standard library modules, numpy, scipy, pandas, and matplotlib.
  • Ephemeral Storage: Files written during the sandbox run are discarded immediately after the request finishes.

Key References


Dependencies

  • google-genai>=0.1.1

04 同仓库更多 Skills

Lord1Egypt
Lord1Egypt/ai-skillforge

zarr-python

Chunked N-D arrays for cloud storage. Compressed arrays, parallel I/O, S3/GCS integration, NumPy/Dask/Xarray compatible, for large-scale scientific computing pipelines.

★ 2
Lord1Egypt
Lord1Egypt/ai-skillforge

what-if-oracle

Run structured What-If scenario analysis with multi-branch possibility exploration. Use this skill when the user asks speculative questions like "what if...", "what would happen if...", "what are the possibilities", "explore scenarios", "scenario analysis", "possibility space", "what could go wrong", "best case / worst case", "risk analysis", "contingency planning", "strategic options", or any question about uncertain futures. Also trigger when the user faces a fork-in-the-road decision, wants to stress-test an idea, or needs to think through consequences before committing.

★ 2
Lord1Egypt
Lord1Egypt/ai-skillforge

venue-templates

Access comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.

★ 2
Lord1Egypt
Lord1Egypt/ai-skillforge

vaex

Use this skill for processing and analyzing large tabular datasets (billions of rows) that exceed available RAM. Vaex excels at out-of-core DataFrame operations, lazy evaluation, fast aggregations, efficient visualization of big data, and machine learning on large datasets. Apply when users need to work with large CSV/HDF5/Arrow/Parquet files, perform fast statistics on massive datasets, create visualizations of big data, or build ML pipelines that do not fit in memory.

★ 2
Lord1Egypt
Lord1Egypt/ai-skillforge

usfiscaldata

Query the U.S. Treasury Fiscal Data API for federal financial data including national debt, government spending, revenue, interest rates, exchange rates, and savings bonds. Access 54 datasets and 182 data tables with no API key required. Use when working with U.S. federal fiscal data, national debt tracking (Debt to the Penny), Daily Treasury Statements, Monthly Treasury Statements, Treasury securities auctions, interest rates on Treasury securities, foreign exchange rates, savings bonds, or any U.S. government financial statistics.

★ 2
Lord1Egypt
Lord1Egypt/ai-skillforge

treatment-plans

Generate concise (3-4 page), focused medical treatment plans in LaTeX/PDF format for all clinical specialties. Supports general medical treatment, rehabilitation therapy, mental health care, chronic disease management, perioperative care, and pain management. Includes SMART goal frameworks, evidence-based interventions with minimal text citations, regulatory compliance (HIPAA), and professional formatting. Prioritizes brevity and clinical actionability.

★ 2