code-interpreter template includes Jupyter kernels for:
- Python
- JavaScript
- TypeScript
- R
- Java
- Bash
language= when you run an isolated cell, or set the language on a code
context when you want multiple cells to share kernel state.
result = machine.run_code("console.log(1 + 2)", language="javascript")
print("".join(result.logs.stdout))
ctx = machine.code_interpreter.create_code_context(language="r", cwd="/workspace")
machine.code_interpreter.run_code("x <- c(1, 2, 3)", context=ctx)
result = machine.code_interpreter.run_code("mean(x)", context=ctx)
print(result.results[0].text)
const result = await machine.code.run("console.log(1 + 2)", { language: "javascript" });
console.log(result.logs.stdout.join(""));
const ctx = await machine.code.createContext({ language: "r", cwd: "/workspace" });
await machine.code.run("x <- c(1, 2, 3)", { context: ctx });
const r = await machine.code.run("mean(x)", { context: ctx });
console.log(r.results[0].text);
nullspace machine code run mch_123 "console.log(1 + 2)" --language javascript
nullspace machine code context create mch_123 --language r --cwd /workspace
nullspace machine code run mch_123 "x <- c(1, 2, 3)" --context <context-id>
nullspace machine code run mch_123 "mean(x)" --context <context-id>
# 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": "console.log(1 + 2)", "language": "javascript"}'
# create an R context, then run against its 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": "r", "cwd": "/workspace"}'
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": "x <- c(1, 2, 3)", "context_id": "<context-id>"}'
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": "mean(x)", "context_id": "<context-id>"}'