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

# Write code, then run it

> Agent writes a script with Claude, then executes it via Judge0 to verify the output. Two paid calls, ~$0.04.

Most agent demos stop at "the LLM wrote some code." This one closes the loop — Claude writes the script, the agent pays Judge0 to actually execute it, and the verified output flows back. Useful when you want machine-verified correctness, not just plausible-looking code.

***

## The prompt

```
Use t2 services. Write a self-contained Python script that computes the 30-day EMA of a daily
close series. Embed ~40 days of sample SUI closes in the script as test data,
then run it via Judge0 to verify the final EMA value.
```

<Note>
  The prompt is deliberately **self-contained** — the script carries its own sample
  data, so nothing needs to be uploaded. Judge0's sandbox can't read your local
  files anyway; embedding the data is what makes the "verify" step real (the agent
  proves the EMA *logic* executes correctly on a known series). To run it on your
  own OHLC data, paste a few rows into the prompt or pipe a CSV via `stdin` as the
  SDK example below shows.
</Note>

***

## What runs

1. `POST /anthropic/v1/messages` — Claude writes Python (\~\$0.02)
2. `POST /judge0/v1/submissions` — Judge0 executes it in a sandbox (\~\$0.02)

Judge0 supports [70+ languages](https://judge0.com/languages) — Python, Node.js, Go, Rust, Bash, SQL, etc. The same recipe works for any of them; swap the `language_id`.

***

## Run it

### SDK

```typescript theme={null}
import { T2000 } from '@t2000/sdk';

const agent = await T2000.create();

// 40 days of self-contained sample SUI closes — swap in your own
// OHLC `close` column to run it for real. No upload needed.
const closes = Array.from({ length: 40 }, (_, i) =>
  (0.85 + 0.15 * Math.sin(i / 5) + i * 0.004).toFixed(4),
);
const csv = ['close', ...closes].join('\n');

const script = await agent.pay({
  url: 'https://mpp.t2000.ai/anthropic/v1/messages',
  method: 'POST',
  headers: { 'anthropic-version': '2023-06-01' },
  body: JSON.stringify({
    model: 'claude-sonnet-4-5',
    max_tokens: 1024,
    messages: [{
      role: 'user',
      content:
        "Write a Python script that reads a CSV with a 'close' column from " +
        'stdin and prints the 30-day EMA (seeded with a 30-period SMA) of the ' +
        'last row. Output ONLY the script, no commentary.',
    }],
  }),
});

const code = (script.body as { content: { text: string }[] }).content[0].text;

const run = await agent.pay({
  url: 'https://mpp.t2000.ai/judge0/v1/submissions',
  method: 'POST',
  body: JSON.stringify({
    source_code: Buffer.from(code).toString('base64'),
    language_id: 71, // Python 3
    stdin: Buffer.from(csv).toString('base64'),
  }),
});

const output = (run.body as { stdout: string }).stdout;
console.log('30-day EMA:', Buffer.from(output, 'base64').toString());
```

### CLI

```bash theme={null}
SCRIPT=$(t2 pay https://mpp.t2000.ai/anthropic/v1/messages \
  --header 'anthropic-version: 2023-06-01' \
  --data '{"model":"claude-sonnet-4-5","max_tokens":1024,"messages":[{"role":"user","content":"Write a Python one-liner that prints fib(10)."}]}')

# extract code, base64 it, submit:
echo "$SCRIPT" | jq -r '.content[0].text' | base64 > /tmp/code.b64

t2 pay https://mpp.t2000.ai/judge0/v1/submissions \
  --data "{\"source_code\":\"$(cat /tmp/code.b64)\",\"language_id\":71}"
```

***

## Expected output

```
2 calls · ~$0.04 · ~3s · 0 taps
30-day EMA: ~0.96   (exact value depends on the sample close series)
```

(The minimal CLI snippet below runs `fib(10)` instead and prints `55` — same write-then-run loop, simplest possible payload.)

***

## Extend it

* Swap to **Together** (`/together/v1/chat/completions`) for Llama-4 code generation at the same price
* Use **Judge0 `/v1/languages`** (\~\$0.02) to discover available runtimes if you want to branch on language
* Pipe the verified output into **Firecrawl** (`/firecrawl/v1/scrape`) to compare against data scraped from another source
* Pair with **OpenAI** (`/openai/v1/chat/completions`) as a second opinion — have one model write the code, the other review it before Judge0 runs it
