Python is the default code interpreter language on the standard code-interpreter template.
result = machine.run_code("""
import numpy as np

values = np.array([1, 2, 3])
values.mean()
""", language="python")

print(result.results[0].text)
const result = await machine.code.run(`
import numpy as np

values = np.array([1, 2, 3])
values.mean()
`, { language: "python" });

console.log(result.results[0].text);
nullspace machine code run mch_123 "import numpy as np

values = np.array([1, 2, 3])
values.mean()" --language python
# returns a Server-Sent Events stream of JSON events
curl -N -X POST "${NULLSPACE_API_URL}/v1/machines/mch_123/code/execute" \
  -H "Authorization: Bearer ${NULLSPACE_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{"code": "import numpy as np\nvalues = np.array([1, 2, 3])\nvalues.mean()", "language": "python"}'
Use a Python context when later cells should reuse imports and variables:
ctx = machine.code_interpreter.create_code_context(language="python")
machine.code_interpreter.run_code("import pandas as pd", context=ctx)
machine.code_interpreter.run_code("df = pd.DataFrame({'x': [1, 2, 3]})", context=ctx)
result = machine.code_interpreter.run_code("df['x'].sum()", context=ctx)
const ctx = await machine.code.createContext({ language: "python" });
await machine.code.run("import pandas as pd", { context: ctx });
await machine.code.run("df = pd.DataFrame({'x': [1, 2, 3]})", { context: ctx });
const result = await machine.code.run("df['x'].sum()", { context: ctx });
nullspace machine code context create mch_123 --language python
nullspace machine code run mch_123 "import pandas as pd" --context <context-id>
nullspace machine code run mch_123 "df = pd.DataFrame({'x': [1, 2, 3]})" --context <context-id>
nullspace machine code run mch_123 "df['x'].sum()" --context <context-id>
curl -X POST "${NULLSPACE_API_URL}/v1/machines/mch_123/code/contexts" \
  -H "Authorization: Bearer ${NULLSPACE_API_KEY}" \
  -H "Content-Type: application/json" -d '{"language": "python"}'
# then run each cell against the returned context id (SSE stream)
curl -N -X POST "${NULLSPACE_API_URL}/v1/machines/mch_123/code/execute" \
  -H "Authorization: Bearer ${NULLSPACE_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{"code": "import pandas as pd", "context_id": "<context-id>"}'
Install additional Python packages into the running machine with install_packages().