Codeinterpreter

Learn how to use Codeinterpreter with Composio

Overview

SLUG: CODEINTERPRETER

Description

CodeInterpreter extends Python-based coding environments with integrated data analysis, enabling developers to run scripts, visualize results, and prototype solutions inside supported platforms

Tools

Executing tools

Python
1from composio import Composio
2from openai import OpenAI
3import json
4
5openai = OpenAI()
6composio = Composio()
7
8# User ID must be a valid UUID format
9user_id = "0000-0000-0000" # Replace with actual user UUID from your database
10
11tools = composio.tools.get(user_id=user_id, toolkits=["CODEINTERPRETER"])
12
13print("[!] Tools:")
14print(json.dumps(tools))
15
16def invoke_llm(task = "What can you do?"):
17 completion = openai.chat.completions.create(
18 model="gpt-4o",
19 messages=[
20 {
21 "role": "user",
22 "content": task, # Your task here!
23 },
24 ],
25 tools=tools,
26 )
27
28 # Handle Result from tool call
29 result = composio.provider.handle_tool_calls(user_id=user_id, response=completion)
30 print(f"[!] Completion: {completion}")
31 print(f"[!] Tool call result: {result}")
32
33invoke_llm()

Tool List

Tool Name: Create Sandbox

Description

Create a sandbox to execute python code in a jupyter notebook cell. this is useful for agents to communicate, execute code, see output, read files, write files, etc. it's like you own personal computer, but in the cloud. use /home/user folder to write/read files.

Action Parameters

keep_alive
integerDefaults to 300

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Execute Code

Description

Execute python code in a sandbox and return any result, stdout, stderr, and error. use /home/user folder to write/read files. try to not use plt.show() as the code is executed remotely. use files for image/chart output instead.

Action Parameters

code_to_execute
stringRequired
keep_alive
integerDefaults to 300
sandbox_id
string
timeout
integerDefaults to 60

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get File

Description

Get a file from the sandbox and returns the file. the files should be read from /home/user folder.

Action Parameters

file_path
stringRequired
sandbox_id
stringRequired
timeout
integer

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Run Terminal Command

Description

Run a command in the terminal and returns the stdout, stderr, and error code. use /home/user folder to write/read files.

Action Parameters

command
stringRequired
keep_alive
integerDefaults to 300
sandbox_id
string
timeout
integer

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Upload File

Description

Upload a file to the sandbox environment. the files should be uploaded to the /home/user folder.

Action Parameters

destination_path
stringRequired
file
objectRequired
overwrite
boolean
sandbox_id
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired