Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex AI Studio
  • About Yandex AI Studio
  • Getting started with Model Gallery
  • Yandex Workflows
    • All guides
    • Disabling request logging
    • Getting an API key
      • Creating a simple text agent
      • Creating a text agent with a function call
      • Creating a voice agent via Realtime API
      • Completing a task with Code Interpreter
      • Managing conversation context
  • Switching from the AI Assistant API to Responses API
  • Compatibility with OpenAI
  • Quotas and limits
  • Pricing policy
  • Access management
  • Audit Trails events
  • Public materials
  • Release notes
  • Terms and definitions

In this article:

  • Getting started
  • Create an agent
  1. Step-by-step guides
  2. Agent Atelier
  3. Completing a task with Code Interpreter

Completing a task with Code Interpreter

Written by
Yandex Cloud
Updated at February 25, 2026
  • Getting started
  • Create an agent

In Yandex Cloud AI Studio, you can use Code Interpreter to extend the model's functionality so it can write and execute Python code in an isolated test environment. This tool will prove useful in tasks where the model calculates, validates, and transforms data instead of being limited to textual reasoning.

Note

Sessions with Code Interpreter are context-loaded (code, data, execution results). We recommend models with a large context window for these sessions, e.g., Qwen.

Getting startedGetting started

To use an example:

Python
  1. Create a service account and assign the ai.assistants.editor and ai.languageModels.user roles to it.

  2. Get and save the service account's API key with yc.ai.foundationModels.execute for its scope.

    Note

    If you are using Windows, we recommend installing the WSL shell first and using it to proceed.

  3. Install Python 3.10 or higher.

  4. Install Python venv to create isolated virtual environments in Python.

  5. Create a new Python virtual environment and activate it:

    python3 -m venv new-env
    source new-env/bin/activate
    
  6. Install the OpenAI library for Python:

    pip install openai
    

Create an agentCreate an agent

Python
  1. Create a file named Presentation.py and add the following code to it:

    import openai
    import json
    import os     
    
    YC_MODEL = "qwen3-235b-a22b-fp8"
    YC_API_KEY = os.getenv('YC_API_KEY')
    YC_FOLDER_ID = os.getenv('YC_FOLDER_ID')
    
    client = openai.OpenAI(
        api_key=YC_API_KEY,
        base_url="https://ai.api.cloud.yandex.net/v1",
        project=YC_FOLDER_ID
    )
    
    instruction = """
    You are a Python programmer and can write and run code to solve the task you are given.
    First, check if you have the necessary libraries, and if not, install them.
    """
    
    prompt = """
    Give me a detailed pptx presentation on derivatives: what they are, how to calculate them. Add some infographics.
    There must be at least 5 slides in the presentation.
    """
    
    stream = client.responses.create(
        model=f"gpt://{YC_FOLDER_ID}/{YC_MODEL}",
        input=prompt,
        tool_choice="auto",
        temperature=0.3,
        tools=[
            {
                "type": "code_interpreter",
                "container": {
                    "type": "auto",
                }
            }
        ],
        stream=True
    )
    
    resp_id = None
    
    print("Request processing started...\n")
    
    for event in stream:
        if event.type == "response.output_text.delta":
            print(event.delta, end='')
        elif event.type == "response.code_interpreter_call_code.delta":
            print(event.delta, end='')
        elif event.type == "response.reasoning_text.delta":
            print(event.delta, end='')
        elif event.type == "response.reasoning_summary_text.delta":
            print(event.delta, end='')
        elif event.type == "response.code_interpreter_call_code.done":
            print(f"\n\nFinal code:\n{event.code}\n")
        elif event.type == "response.code_interpreter_call.in_progress":
            print("\n[Executing the code...]\n")
        elif event.type == "response.code_interpreter_call.done":
            print("\n[Code executed]\n")
        elif event.type == "response.in_progress":
            resp_id = event.response.id
            print(f"\n[Processing the {resp_id} response]\n")
    
    print(f"\n\nTask solved: {resp_id}\n")
    print("=" * 50 + "\n")
    
    # Getting a full response
    response = client.responses.retrieve(resp_id)
    
    # Processing results and downloading files
    print("Processing the execution results:")
    os.makedirs("./downloaded_files", exist_ok=True)
    
    downloaded_count = 0
    for item in response.output:
        # Outputting code execution results
        if item.type == "code_interpreter_call":
            print("\nCode:\n")
            print(item.code, '\n')
            for output_item in item.outputs:
                output_type = output_item.type
                logs = output_item.logs.strip()
                if logs:
                    print(f"[{output_type.upper()}] Output:")
                    for log_line in logs.split('\n'):
                        print(f"        {log_line}")
    
        # Downloading files from a container
        elif item.type == "message":
            for content in item.content:
                # Checking for annotations with files
                if hasattr(content, 'annotations') and content.annotations:
                    for annotation in content.annotations:
                        if annotation.type == "container_file_citation":
                            file_id = annotation.file_id
                            file_name = annotation.filename
    
                            print(f"\n📎 File found: {file_name} (ID: {file_id})")
    
                            try:
                                # Downloading file
                                file_content = client.files.content(file_id)
                                
                                # Saving locally
                                local_path = os.path.join("./downloaded_files", file_name)
                                with open(local_path, 'wb') as f:
                                    f.write(file_content.read())
                                
                                print(f"✅ File saved: {local_path}")
                                downloaded_count += 1
                            except Exception as e:
                                print(f"❌ Error downloading {file_name}: {e}")
    
    if downloaded_count > 0:
        print(f"\n✅ Total files downloaded: {downloaded_count}")
    else:
        print("\nℹ️  No files found for download.")
    
    print("\n" + "=" * 50 + "\n")
    
    # Full response
    print("Full response (JSON):")
    print(json.dumps(response.model_dump(), indent=2, ensure_ascii=False))
    
  2. Save authentication data into environment variables:

    export YC_FOLDER_ID=<folder_ID>
    export YC_API_KEY=<API_key>
    
  3. Run the file you created:

    python presentation.py
    

Next to the file, a folder named downloaded_files will be created containing the model's output: an PPTX presentation and graphs. A progress report will be sent to the console.

Response fragment
I have successfully created a detailed PowerPoint (PPTX) presentation on derivatives for you. The presentation contains **6 slides**, including the title slide, theoretical explanations, differentiation rules, examples, a graphical interpretation with infographics, and info on real-life use of derivatives.

### Presentation contents:
1. **Title slide**: Title and subtitle.
2. **What is a derivative?**: Definition, geometrical meaning, notation.
3. **Differentiation rules**: Basic formulas and laws.
4. **Calculation examples**: Step-by-step calculations for various functions.
5. **Graphical interpretation**: Graph of the \(y = x^2 \) function and tangent at the \(x = 1 \) point (with visualization).
6. **Use of derivatives**: Physics, economics, machine learning, other fields.

...

📎 File found: Proizvodnye_Presentation.pptx (ID: fvttk7sto2ne********)
✅ File saved: ./downloaded_files\Proizvodnye_Presentation.pptx

📎 File found: tangent_plot.png (ID: fvtt18umj1gn********)
✅ File saved: ./downloaded_files\tangent_plot.png

✅ Total files downloaded: 2

Was the article helpful?

Previous
Creating a voice agent via Realtime API
Next
Managing conversation context
© 2026 Direct Cursus Technology L.L.C.