Code interpreter
Sandboxed Python for the arithmetic a model should not do in its head — a deadline, an interest figure, a share of an estate.
code_interpreter runs Python the model wrote, inside a container built to hold nothing valuable and reach nothing else. It answers by executing, not by estimating — asked directly, the same model that runs this can misremember a deadline; the code it runs to compute one does not.
The sandbox
A fresh container per call, removed the moment it finishes. Nothing about one run is visible to the next — not a file, not a variable, not an installed package.
| Constraint | Value |
|---|---|
| Network | None — no interface to reach anything through, not firewalled traffic. It cannot reach the model servers, your knowledge base, or the open internet. |
| Filesystem | Read-only, plus two small tmpfs mounts (64 MB) that vanish with the container. |
| Privilege | Runs as nobody, every Linux capability dropped, no-new-privileges set. |
| CPU / memory | 1 core, 512 MB, capped process count — a runaway allocation or a fork bomb kills the container, not the host. |
| Timeout | 20 seconds by default, up to whatever your operator has set as the hard ceiling — wall clock, enforced by killing the container. |
| Output | stdout and stderr only, each capped at 200,000 characters. |
What's installed
Python 3.12, plus numpy, pandas, python-dateutil, sympy, matplotlib, openpyxl and tabulate. Neither pip nor requests/urllib3 are present — both were removed on purpose, since there is no network for either to use.
matplotlib is installed and runs, but nothing carries a saved image back out of the container — only stdout and stderr return from a call. Print your results instead of plotting to a file you expect to retrieve; tabulate is there for exactly that.Declaring it
[{ "type": "code_interpreter" }]| Parameter | Type | Description |
|---|---|---|
| code Required | string | The Python source to run. Write a self-contained script — the tool never sends input on stdin, even though the sandbox itself accepts it. |
| timeout Optional | integer | Seconds to allow, capped regardless of what you ask for by whatever ceiling your operator has set. Default: 20 |
- No network — no
pip install, no request to any URL, no reading your knowledge base or the legal corpus. - No files handed back — only what the code prints.
- No state between calls — the next run starts from nothing, every time.
Complete example
One request — the model writes the code, runs it, and answers from the result. The model is larsa-auto, the only one that runs code_interpreter server-side.
curl https://api.console.larsa.larsima.com/v1/chat/completions \
-H "Authorization: Bearer $LARSA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "larsa-auto",
"messages": [{"role": "user", "content":
"A notice period of 45 days starts on 2026-08-26. Give the calendar date it ends on, and the day of the week."}],
"tools": [{"type": "code_interpreter"}]
}'import os
import requests
API = "https://api.console.larsa.larsima.com/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['LARSA_API_KEY']}",
"Content-Type": "application/json"}
res = requests.post(f"{API}/chat/completions", headers=HEADERS, json={
"model": "larsa-auto",
"messages": [{"role": "user", "content":
"A notice period of 45 days starts on 2026-08-26. "
"Give the calendar date it ends on, and the day of "
"the week."}],
"tools": [{"type": "code_interpreter"}],
})
print(res.json()["choices"][0]["message"]["content"])const API = "https://api.console.larsa.larsima.com/v1";
const res = await fetch(`${API}/chat/completions`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LARSA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "larsa-auto",
messages: [{ role: "user", content:
"A notice period of 45 days starts on 2026-08-26. " +
"Give the calendar date it ends on, and the day of " +
"the week." }],
tools: [{ type: "code_interpreter" }],
}),
});
const out = await res.json();
console.log(out.choices[0].message.content);const API = "https://api.console.larsa.larsima.com/v1";
const res = await fetch(`${API}/chat/completions`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LARSA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "larsa-auto",
messages: [{ role: "user", content:
"A notice period of 45 days starts on 2026-08-26. " +
"Give the calendar date it ends on, and the day of " +
"the week." }],
tools: [{ type: "code_interpreter" }],
}),
});
const out = (await res.json()) as any;
console.log(out.choices[0].message.content);package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
body, _ := json.Marshal(map[string]any{
"model": "larsa-auto",
"messages": []map[string]string{{"role": "user", "content":
"A notice period of 45 days starts on 2026-08-26. " +
"Give the calendar date it ends on, and the day of " +
"the week."}},
"tools": []map[string]string{{"type": "code_interpreter"}},
})
req, _ := http.NewRequest("POST",
"https://api.console.larsa.larsima.com/v1/chat/completions",
bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("LARSA_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
raw, _ := io.ReadAll(resp.Body)
var out map[string]any
json.Unmarshal(raw, &out)
choice := out["choices"].([]any)[0].(map[string]any)
fmt.Println(choice["message"].(map[string]any)["content"])
}use serde_json::json;
use std::env;
fn main() {
let key = env::var("LARSA_API_KEY").unwrap();
let client = reqwest::blocking::Client::new();
let out: serde_json::Value = client
.post("https://api.console.larsa.larsima.com/v1/chat/completions")
.bearer_auth(key)
.json(&json!({
"model": "larsa-auto",
"messages": [{"role": "user", "content":
"A notice period of 45 days starts on 2026-08-26. Give the calendar date it ends on, and the day of the week."}],
"tools": [{"type": "code_interpreter"}]
}))
.send().unwrap().json().unwrap();
println!("{}", out["choices"][0]["message"]["content"]);
}import org.json.JSONArray;
import org.json.JSONObject;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class CodeInterpreterExample {
public static void main(String[] args) throws Exception {
JSONObject body = new JSONObject()
.put("model", "larsa-auto")
.put("messages", new JSONArray().put(new JSONObject()
.put("role", "user")
.put("content",
"A notice period of 45 days starts on 2026-08-26. Give the calendar date it ends on, and the day of the week.")))
.put("tools", new JSONArray().put(new JSONObject()
.put("type", "code_interpreter")));
HttpRequest req = HttpRequest.newBuilder(URI.create(
"https://api.console.larsa.larsima.com/v1/chat/completions"))
.header("Authorization", "Bearer " + System.getenv("LARSA_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body.toString()))
.build();
HttpResponse<String> res = HttpClient.newHttpClient()
.send(req, HttpResponse.BodyHandlers.ofString());
JSONObject out = new JSONObject(res.body());
System.out.println(out.getJSONArray("choices")
.getJSONObject(0).getJSONObject("message")
.getString("content"));
}
}using System.Net.Http.Headers;
using System.Text;
using System.Text.Json.Nodes;
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer",
Environment.GetEnvironmentVariable("LARSA_API_KEY"));
var body = new JsonObject {
["model"] = "larsa-auto",
["messages"] = new JsonArray {
new JsonObject { ["role"] = "user", ["content"] =
"A notice period of 45 days starts on 2026-08-26. " +
"Give the calendar date it ends on, and the day of the week." },
},
["tools"] = new JsonArray {
new JsonObject { ["type"] = "code_interpreter" },
},
};
var res = await http.PostAsync(
"https://api.console.larsa.larsima.com/v1/chat/completions",
new StringContent(body.ToJsonString(), Encoding.UTF8,
"application/json"));
var out = JsonNode.Parse(
await res.Content.ReadAsStringAsync())!.AsObject();
Console.WriteLine(out["choices"]![0]!["message"]!["content"]);<?php
$ch = curl_init("https://api.console.larsa.larsima.com/v1/chat/completions");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("LARSA_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"model" => "larsa-auto",
"messages" => [["role" => "user", "content" =>
"A notice period of 45 days starts on 2026-08-26. " .
"Give the calendar date it ends on, and the day of the week."]],
"tools" => [["type" => "code_interpreter"]],
]),
]);
$out = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $out["choices"][0]["message"]["content"], "\n";require "json"
require "net/http"
require "uri"
uri = URI("https://api.console.larsa.larsima.com/v1/chat/completions")
req = Net::HTTP::Post.new(uri,
"Authorization" => "Bearer #{ENV.fetch('LARSA_API_KEY')}",
"Content-Type" => "application/json")
req.body = {
model: "larsa-auto",
messages: [{ role: "user", content:
"A notice period of 45 days starts on 2026-08-26. "\
"Give the calendar date it ends on, and the day of "\
"the week." }],
tools: [{ type: "code_interpreter" }],
}.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts JSON.parse(res.body)["choices"][0]["message"]["content"]