DEV Community

Ozor
Ozor

Posted on • Originally published at api-catalog-three.vercel.app

Run Code in Any Language with One API Call (No Server Required)

You're building an AI agent that writes code. Or an online tutorial platform. Or an automated testing pipeline. You need to execute user-submitted code safely — but setting up Docker containers, sandboxes, and process isolation is a project in itself.

What if you could run code in any language with a single HTTP request?

curl "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/run/python?code=print(sum(range(1,101)))"
Enter fullscreen mode Exit fullscreen mode
{
  "language": "python",
  "exitCode": 0,
  "stdout": "5050",
  "duration": 14
}
Enter fullscreen mode Exit fullscreen mode

That's it. No server setup, no Docker, no infrastructure. Let me show you what you can build with this.


What You Get

The Code Execution API supports 4 languages out of the box:

Language Endpoint Runtime
Python /api/run/python Python 3
JavaScript /api/run/javascript Node.js
TypeScript /api/run/typescript Node.js + tsx
Bash /api/run/bash bash

Every execution runs in an isolated sandbox. Your code can't access the filesystem, network, or other processes. Results come back in milliseconds.


Quick Start: GET Requests

For simple one-liners, use GET with a code query parameter:

Python:

curl "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/run/python?code=print(2**100)"
Enter fullscreen mode Exit fullscreen mode

JavaScript:

curl "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/run/javascript?code=console.log(Math.PI)"
Enter fullscreen mode Exit fullscreen mode

Bash:

curl "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/run/bash?code=echo%20Hello%20World"
Enter fullscreen mode Exit fullscreen mode

Multi-Line Code: POST Requests

For real programs, POST to /api/execute with a JSON body:

curl -X POST "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/execute" \
  -H "Content-Type: application/json" \
  -d '{
    "language": "python",
    "code": "import json\n\ndef fibonacci(n):\n    a, b = 0, 1\n    for _ in range(n):\n        a, b = b, a + b\n    return a\n\nresult = {f\"fib({i})\": fibonacci(i) for i in [10, 20, 30, 50]}\nprint(json.dumps(result, indent=2))"
  }'
Enter fullscreen mode Exit fullscreen mode

Response:

{
  "language": "python",
  "exitCode": 0,
  "stdout": "{\n  \"fib(10)\": 55,\n  \"fib(20)\": 6765,\n  \"fib(30)\": 832040,\n  \"fib(50)\": 12586269025\n}",
  "duration": 12
}
Enter fullscreen mode Exit fullscreen mode

Use Case 1: AI Agent Code Execution

If you're building an AI agent that writes and tests code, this API is the missing piece. Here's a Python function that lets your agent run code safely:

import requests

API = "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/execute"

def run_code(language, code):
    """Execute code and return the result."""
    resp = requests.post(API, json={"language": language, "code": code})
    result = resp.json()

    if result["exitCode"] == 0:
        return result["stdout"]
    else:
        raise RuntimeError(f"Code failed:\n{result['stdout']}")

# Your AI agent generates code, then verifies it works:
agent_code = """
def is_palindrome(s):
    s = s.lower().replace(' ', '')
    return s == s[::-1]

tests = ["racecar", "hello", "A man a plan a canal Panama"]
for t in tests:
    print(f"{t!r}: {is_palindrome(t)}")
"""

output = run_code("python", agent_code)
print(output)
# 'racecar': True
# 'hello': False
# 'A man a plan a canal Panama': True
Enter fullscreen mode Exit fullscreen mode

This pattern is how AI agents validate their own output. Generate code, execute it, check the result, iterate.


Use Case 2: Build a Code Playground Widget

Want to embed a runnable code editor in your blog or docs? Here's a minimal HTML playground:

<!DOCTYPE html>
<html>
<head>
  <title>Code Playground</title>
  <style>
    body { font-family: monospace; max-width: 700px; margin: 2rem auto; }
    textarea { width: 100%; height: 200px; font-family: monospace; font-size: 14px; padding: 12px; }
    select, button { padding: 8px 16px; font-size: 14px; margin: 8px 4px 8px 0; }
    button { background: #2563eb; color: white; border: none; border-radius: 4px; cursor: pointer; }
    pre { background: #1e1e1e; color: #d4d4d4; padding: 16px; border-radius: 4px; overflow-x: auto; }
    .error { color: #f87171; }
  </style>
</head>
<body>
  <h2>Code Playground</h2>
  <select id="lang">
    <option value="python">Python</option>
    <option value="javascript">JavaScript</option>
    <option value="bash">Bash</option>
    <option value="typescript">TypeScript</option>
  </select>
  <button onclick="runCode()">Run</button>
  <span id="timer"></span>
  <textarea id="code">print("Hello, World!")</textarea>
  <pre id="output">Output will appear here...</pre>

  <script>
    const API = 'https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/execute';

    async function runCode() {
      const lang = document.getElementById('lang').value;
      const code = document.getElementById('code').value;
      const output = document.getElementById('output');
      const timer = document.getElementById('timer');

      output.textContent = 'Running...';
      output.className = '';
      const start = Date.now();

      try {
        const resp = await fetch(API, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ language: lang, code })
        });
        const result = await resp.json();
        timer.textContent = `${Date.now() - start}ms`;

        if (result.exitCode === 0) {
          output.textContent = result.stdout || '(no output)';
        } else {
          output.textContent = result.stdout || result.stderr;
          output.className = 'error';
        }
      } catch (err) {
        output.textContent = `Error: ${err.message}`;
        output.className = 'error';
      }
    }
  </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Save this as an HTML file, open it in your browser, and you have a working code playground. No backend needed.


Use Case 3: Automated Testing

Run test suites against student code, validate submissions, or test generated code:

const API = 'https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/execute';

async function testSubmission(studentCode) {
  // Append test cases to the student's code
  const testCode = `
${studentCode}

# --- Test Cases ---
assert add(2, 3) == 5, "add(2, 3) should be 5"
assert add(-1, 1) == 0, "add(-1, 1) should be 0"
assert add(0, 0) == 0, "add(0, 0) should be 0"
print("All tests passed!")
`;

  const resp = await fetch(API, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ language: 'python', code: testCode })
  });
  const result = await resp.json();

  return {
    passed: result.exitCode === 0,
    output: result.stdout,
    duration: result.duration
  };
}

// Test a correct submission
testSubmission('def add(a, b): return a + b')
  .then(r => console.log(r));
// { passed: true, output: "All tests passed!", duration: 12 }
Enter fullscreen mode Exit fullscreen mode

Response Format

Every execution returns the same structure:

{
  "id": "unique-execution-id",
  "language": "python",
  "exitCode": 0,
  "stdout": "program output here",
  "stderr": "",
  "duration": 14,
  "timedOut": false,
  "truncated": false
}
Enter fullscreen mode Exit fullscreen mode
Field Description
exitCode 0 = success, non-zero = error
stdout Standard output from the program
stderr Standard error output
duration Execution time in milliseconds
timedOut Whether execution hit the time limit
truncated Whether output was cut short

Limits and Safety

  • Timeout: Executions have a time limit to prevent infinite loops
  • Sandboxed: Code runs in isolated environments — no file system or network access
  • Output cap: Large outputs are truncated to prevent abuse
  • Rate limited: Fair usage across all consumers

The sandbox ensures that even malicious code can't escape or affect other users.


Getting Started

No API key needed for the code execution endpoints — just start making requests:

# Python
curl "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/run/python?code=print('works!')"

# JavaScript
curl "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/run/javascript?code=console.log('works!')"

# Bash
curl "https://agent-gateway-kappa.vercel.app/v1/agent-coderunner/api/run/bash?code=echo%20works!"
Enter fullscreen mode Exit fullscreen mode

For higher rate limits and access to 40+ other APIs (screenshots, web scraping, crypto prices, DNS, PDF generation), grab a free API key — 200 credits included, no credit card required.

Full API catalog: api-catalog-three.vercel.app


What Else Can You Build?

This is one of 40+ APIs available through the same gateway. Combine code execution with:

All through one API key, one base URL.

If you're building AI agents, check out the MCP Server — it wraps all 40 APIs into tools that Claude, Cursor, and other AI assistants can use natively.

Top comments (0)