> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nonhumans.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Compute: Always-On Runtime & Code Execution

> Run sandboxed code in Python, JavaScript, TypeScript, Bash, and R directly from your agent — with configurable timeouts and no infrastructure to manage.

Your agent does not have to stop when an API call returns. The compute primitive gives your agent an always-on runtime that can execute arbitrary code in an isolated sandbox, process data, run analysis pipelines, and return structured output — all without you provisioning any infrastructure. Everything runs on Nonhumans-managed compute and returns results directly to your agent.

## What Compute Provides

<CardGroup cols={2}>
  <Card title="Sandboxed Code Execution" icon="shield-halved">
    Run Python, JavaScript, TypeScript, Bash, and R in an isolated sandbox with configurable timeouts and resource limits.
  </Card>

  <Card title="Always-On Runtime" icon="circle-dot">
    Your agent process stays alive between calls. No cold starts, no lost in-memory state — the loop runs continuously until you stop it.
  </Card>

  <Card title="Multi-Language Support" icon="code">
    Execute Python data pipelines, Node.js scripts, TypeScript without a compile step, Bash utilities, and R statistical routines in the same agent.
  </Card>

  <Card title="Structured Output" icon="brackets-curly">
    Stdout, stderr, and exit code are captured and returned synchronously so your agent can act on results immediately.
  </Card>
</CardGroup>

## Running Code

Use `agent.compute.run()` to execute code in a sandboxed environment. Provide the language, the source code, and an optional timeout. Output, errors, and the exit code are returned when execution completes.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Nonhumans } from '@nonhumans/sdk';

  const agent = new Nonhumans({ apiKey: process.env.NONHUMANS_API_KEY });

  const result = await agent.compute.run({
    language: "python",
    code: `
  import json, statistics

  data = [12, 45, 7, 23, 89, 34, 56]
  summary = {
      "mean": statistics.mean(data),
      "median": statistics.median(data),
      "stdev": round(statistics.stdev(data), 2),
  }
  print(json.dumps(summary))
    `,
    timeout: 30,   // seconds; max 300
  });

  console.log(result.stdout);   // '{"mean": 38, "median": 34, "stdev": 28.15}'
  console.log(result.stderr);   // "" (empty if no errors)
  console.log(result.exitCode); // 0
  ```

  ```python Python theme={null}
  import os
  from nonhumans import Nonhumans

  agent = Nonhumans(api_key=os.environ["NONHUMANS_API_KEY"])

  result = agent.compute.run(
      language="python",
      code="""
  import json, statistics

  data = [12, 45, 7, 23, 89, 34, 56]
  summary = {
      "mean": statistics.mean(data),
      "median": statistics.median(data),
      "stdev": round(statistics.stdev(data), 2),
  }
  print(json.dumps(summary))
  """,
      timeout=30,
  )

  print(result.stdout)    # '{"mean": 38, "median": 34, "stdev": 28.15}'
  print(result.stderr)    # ""
  print(result.exit_code) # 0
  ```
</CodeGroup>

## Parameters

<ParamField body="language" type="string" required>
  Runtime to use. One of `python`, `javascript`, `typescript`, `bash`, or `r`.
</ParamField>

<ParamField body="code" type="string" required>
  Source code to execute. Multiline strings are supported.
</ParamField>

<ParamField body="timeout" type="number">
  Maximum execution time in seconds. Default `30`, maximum `300`. Execution is terminated if the limit is reached.
</ParamField>

## Supported Languages

| Language     | Runtime     | Notes                                  |
| ------------ | ----------- | -------------------------------------- |
| `python`     | Python 3.12 | Full stdlib; common packages available |
| `javascript` | Node.js 22  | npm packages available                 |
| `typescript` | Deno 2      | No compile step required               |
| `bash`       | Bash 5.2    | Runs in isolated shell                 |
| `r`          | R 4.4       | CRAN packages available                |

## Example: Data Analysis

Your agent can run data analysis inline, without piping results through an external service. Here is an example that processes a JSON dataset and returns a statistical summary:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Nonhumans } from '@nonhumans/sdk';

  const agent = new Nonhumans({ apiKey: process.env.NONHUMANS_API_KEY });

  const result = await agent.compute.run({
    language: "python",
    code: `
  import json

  sales = [4200, 3800, 5100, 4750, 6300, 5900, 4400]
  total = sum(sales)
  average = total / len(sales)
  peak = max(sales)

  print(json.dumps({"total": total, "average": round(average, 2), "peak": peak}))
    `,
    timeout: 15,
  });

  const summary = JSON.parse(result.stdout);
  console.log(`Total sales: $${summary.total}`);
  console.log(`Average: $${summary.average}`);
  console.log(`Peak month: $${summary.peak}`);
  ```

  ```python Python theme={null}
  import os, json
  from nonhumans import Nonhumans

  agent = Nonhumans(api_key=os.environ["NONHUMANS_API_KEY"])

  result = agent.compute.run(
      language="python",
      code="""
  import json

  sales = [4200, 3800, 5100, 4750, 6300, 5900, 4400]
  total = sum(sales)
  average = total / len(sales)
  peak = max(sales)

  print(json.dumps({"total": total, "average": round(average, 2), "peak": peak}))
  """,
      timeout=15,
  )

  summary = json.loads(result.stdout)
  print(f"Total sales: ${summary['total']}")
  print(f"Average: ${summary['average']}")
  print(f"Peak month: ${summary['peak']}")
  ```
</CodeGroup>

## Use Cases

<CardGroup cols={2}>
  <Card title="Data Processing" icon="chart-bar">
    Run statistical analysis, data cleaning, and transformation pipelines on demand — no separate data infrastructure required.
  </Card>

  <Card title="Report Generation" icon="file-lines">
    Execute code that produces formatted output your agent can embed directly in emails, documents, or API responses.
  </Card>

  <Card title="Automated Validation" icon="circle-check">
    Run validation scripts against incoming data before your agent acts on it, catching errors before they propagate.
  </Card>

  <Card title="Dynamic Scripting" icon="wand-magic-sparkles">
    Generate code at runtime using an LLM, then execute it immediately — closing the loop between reasoning and action.
  </Card>
</CardGroup>

<Info>
  Sandbox environments are stateless between `compute.run()` calls. If you need data to carry over between executions, use the [Memory primitive](/primitives/memory) to store and retrieve it, or pass it explicitly in the `code` string.
</Info>
