Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.gravixlayer.ai/llms.txt

Use this file to discover all available pages before exploring further.

Basic Execution

from gravixlayer import GravixLayer

client = GravixLayer()
runtime = client.runtime.create(template="python-3.14-base-small")

result = runtime.run_code(code="import math\nprint(math.sqrt(81))")
print(result.text)  # 9.0

runtime.kill()

Error Handling

from gravixlayer import GravixLayer

client = GravixLayer()
runtime = client.runtime.create(template="python-3.14-base-small")

result = runtime.run_code(code="raise ValueError('example')")

if not result.success and result.error:
    print(result.error.name)       # ValueError
    print(result.error.value)      # example
    print(result.error.traceback)  # Full traceback

runtime.kill()

With Code Context

Preserve variables across multiple run_code calls:
from gravixlayer import GravixLayer

client = GravixLayer()
runtime = client.runtime.create(template="python-3.14-base-small")

ctx = client.runtime.create_context(runtime.runtime_id)

client.runtime.run_code(runtime.runtime_id, code="x = 42", context_id=ctx.context_id)

result = client.runtime.run_code(runtime.runtime_id, code="print(x + 1)", context_id=ctx.context_id)
print(result.text)  # 43

runtime.kill()

Parameters

ParameterTypeRequiredDescription
codestringYesPython source code to execute
languagestringNo"python" (default) or "javascript"
context_idstringNoReuse a persistent code context
environmentobjectNoPer-execution environment variables
timeoutintegerNoExecution timeout in seconds

Response

FieldTypeDescription
textstringCombined stdout output
successbooleanTrue if no execution error
errorobjectError details (name, value, traceback)
resultslistStructured execution results
logsobjectstdout and stderr as lists of strings