Use this file to discover all available pages before exploring further.
Using a coding agent? Install the together-sandboxes skill to let your agent write correct sandbox code automatically. Learn more.
Together Code Interpreter (TCI) enables you to execute Python code in a sandboxed environment.The Code Interpreter currently only supports Python. We plan to expand the language options in the future.
ℹ️ MCP ServerTCI is also available as an MCP server through Smithery. This makes it easier to add code interpreting abilities to any MCP client like Cursor, Windsurf, or your own chat app.
from together import Togetherclient = Together()## Run a simple print statement in the code interpreterresponse = client.code_interpreter.run( code='print("Welcome to Together Code Interpreter!")', language="python",)print(f"Status: {response.data.status}")for output in response.data.outputs: print(f"{output.type}: {output.data}")
Output
Text
Status: completedstdout: Welcome to Together Code Interpreter!
ℹ️ Pricing informationTCI usage is billed at $0.03/session. As detailed below, sessions have a lifespan of 60 minutes and can be used multiple times.
Reinforcement learning (RL) training: TCI transforms code execution into an interactive RL environment where generated code is run and evaluated in real time, providing reward signals from successes or failures, integrating automated pass/fail tests, and scaling easily across parallel workers—thus creating a powerful feedback loop that refines coding models over many trials.
Developing agentic workflows: TCI allows AI agents to seamlessly write and execute Python code, enabling robust, iterative, and secure computations within a closed-loop system.
Together AI has created sessions to measure TCI usage.A session is an active code execution environment that can be called to execute code, they can be used multiple times and have a lifespan of 60 minutes.Typical TCI usage follows this workflow:
Start a session (create a TCI instance).
Call that session to execute code; TCI outputs stdout and stderr.
Optionally reuse an existing session by calling its session_id.
Reusing sessions and maintaining state between runs
The session_id can be used to access a previously initialized session. All packages, variables, and memory will be retained.
from together import Togetherclient = Together()## set a variable x to 42response1 = client.code_interpreter.run(code="x = 42", language="python")session_id = response1.data.session_id## print the value of xresponse2 = client.code_interpreter.run( code='print(f"The value of x is {x}")', language="python", session_id=session_id,)for output in response2.data.outputs: print(f"{output.type}: {output.data}")
Together Code Interpreter is a very powerful tool and gives you access to a fully functional coding environment. You can install Python libraries and conduct fully fledged data analysis experiments.
from together import Togetherclient = Together()## Create a code interpreter instancecode_interpreter = client.code_interpretercode = """!pip install numpyimport numpy as np## Create a random matrixmatrix = np.random.rand(3, 3)print("Random matrix:")print(matrix)## Calculate eigenvalueseigenvalues = np.linalg.eigvals(matrix)print("\\nEigenvalues:")print(eigenvalues)"""response = code_interpreter.run(code=code, language="python")for output in response.data.outputs: print(f"{output.type}: {output.data}")if response.data.errors: print(f"Errors: {response.data.errors}")
TCI’s Python sessions come pre-installed with the following dependencies, any other dependencies can be installed using a !pip install command in the python code.
from together import Togetherclient = Together()response = client.code_interpreter.sessions.list()for session in response.data.sessions: print(session.id)