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.

Gravix Layer provides isolated agent runtimes that your LLM application can use to run generated code, execute commands, and manage files.

Integration Pattern

  1. Receive a user request.
  2. Create or reuse an agent runtime.
  3. Execute LLM-generated code or terminal commands.
  4. Read outputs and files.
  5. Return results to the user.
  6. Clean up runtime resources.

Example

from gravixlayer import GravixLayer


def run_task(code: str) -> str:
    client = GravixLayer()
    runtime = None

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

        result = runtime.run_code(code=code)

        if result.success:
            return result.text
        return f"Error: {result.error.value if result.error else 'unknown'}"

    finally:
        if runtime:
            runtime.kill()

Best Practices

  • Store API keys in environment variables, never in code.
  • Always clean up runtimes in finally blocks.
  • Use code contexts to persist state across multiple run_code calls.
  • Use run_cmd for package installs and shell operations.
  • Set appropriate timeouts for long-running workloads.

Code Execution

Run Python and JavaScript

Terminal

Shell commands and scripts