Skip to main content
Glama

colab_execute

Execute Python code on Google Colab GPU/TPU runtimes, with support for multiple accelerators, background jobs, and Google Drive file integration.

Instructions

Execute Python code on a Google Colab GPU/TPU runtime.

Primary tool for running GPU/TPU-accelerated Python code (ML training, inference, CUDA operations). Allocates hardware, runs the code, and returns structured JSON with per-cell output, errors, and stderr.

After execution:

  • If background=True, poll with colab_poll(job_id) for results.

  • If OOM error occurs, reduce batch_size or upgrade to A100/H100.

  • If import error, add pip install <pkg> before your main code.

  • To persist outputs to Google Drive, use the drive_save parameter.

  • To pre-load data from Drive, use the drive_fetch parameter.

Common issues:

  • QUOTA_EXCEEDED: Colab rate limit hit. Wait a few minutes or switch to a different accelerator type.

  • CUDA_ERROR: Driver mismatch or GPU init failure. Retry, or try T4.

  • Only ONE background job can run at a time (Colab limitation).

Args: code: Python code to execute on the Colab runtime. accelerator: Hardware accelerator type. Default: "T4". GPU types: "T4" - NVIDIA Tesla T4 (16 GB, free-tier) "L4" - NVIDIA L4 (24 GB, Colab Pro) "A100" - NVIDIA A100 (40 GB, Colab Pro/Pro+) "H100" - NVIDIA H100 (80 GB, Colab Pro+) "G4" - NVIDIA G4 (Colab Pro+) TPU types: "V5E1" - TPU v5e-1 (Colab Pro+) "V6E1" - TPU v6e-1 (Colab Pro+) high_memory: Enable high-memory runtime (more RAM). Default: False. timeout: Max execution time in seconds (10-3600). Default: 300. background: Run in background (non-blocking). Default: False. When True, returns immediately with a job_id that can be polled via colab_poll. Incompatible with drive_fetch/drive_save. drive_fetch: JSON mapping Drive paths to Colab paths. Files are downloaded from Google Drive BEFORE your code runs. Example: '{"colab_data/train.csv": "/content/train.csv"}' Requires prior colab_drive_upload to place files on Drive. drive_save: JSON mapping Colab paths to Drive paths. Files are uploaded to Google Drive AFTER your code finishes, using a freshly obtained token (safe for long-running tasks). Example: '{"/content/model.pt": "results/model.pt"}'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
timeoutNo
backgroundNo
drive_saveNo
acceleratorNoT4
drive_fetchNo
high_memoryNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations are minimal (readOnlyHint=false, destructiveHint=false), so the description carries full burden. It extensively discloses behaviors: hardware allocation, structured JSON return, background job limitations (only one at a time), error handling for OOM, import errors, rate limits, and CUDA errors. It also explains side effects of drive_fetch/drive_save and the need for fresh tokens.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear first sentence, followed by execution context, common issues, and a parameter list. It is front-loaded with key information. However, it is somewhat lengthy; a slightly more concise breakdown could improve readability, but the level of detail is justified by the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (7 parameters, background jobs, accelerator types, drive integration), the description covers all essential aspects: purpose, usage flow, error scenarios, parameter details, and return behavior. It also references sibling tools (colab_poll) and notes limitations, making it a complete guide for the agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description compensates fully with detailed parameter explanations: accelerator types with GPU/TPU lists, examples for drive_fetch/drive_save, defaults, and constraints (e.g., background incompatible with drive operations). This goes well beyond what the bare schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Execute Python code on a Google Colab GPU/TPU runtime,' providing a specific verb and resource. It distinguishes itself from siblings by positioning as the 'primary tool' for running GPU/TPU-accelerated code and mentions background execution with polling, which differentiates it from other execute tools like colab_execute_file or colab_execute_notebook.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives clear context on when to use the tool (primary for GPU/TPU code) and includes after-execution steps (polling, error handling) and common issues. However, it lacks explicit guidance on when NOT to use this tool versus specific siblings, such as using colab_execute_file for file-based execution or colab_execute_notebook for notebooks.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mio-github/mcp-colab-gpu'

If you have feedback or need assistance with the MCP directory API, please join our Discord server