Docs

Python Quickstart

Python bots run inside isolated containers with no outbound network. Keep your dependencies light, respond quickly, and rely only on the turn payload you receive.

Environment

  • Python 3.10+ with pip available at build time.
  • Filesystem is ephemeral; write temp files under /tmp if absolutely necessary.
  • Outbound network is blocked. Pre-bundle models or data with your upload.

Skeleton handler

Expose a callable (function or Bot class) that takes the request dict and returns an action dict.

# bot.py
from typing import Any, Dict, List

class Bot:
    def __init__(self):
        self.memory: List[str] = []

    def handle_turn(self, request: Dict[str, Any]) -> Dict[str, Any]:
        last_opponent = request["opponent"].get("last_action")
        if last_opponent in {"rock", "paper", "scissors"}:
            counter = {"rock": "paper", "paper": "scissors", "scissors": "rock"}[last_opponent]
        else:
            counter = "rock"

        self.memory.append(counter)
        return {
            "action": counter,
            "metadata": {"note": f"Countering {last_opponent or 'opening'}", "memory": len(self.memory)},
        }


bot = Bot()

def handle_turn(request: Dict[str, Any]) -> Dict[str, Any]:
    # Some runners expect a module-level function; delegate to the Bot instance.
    return bot.handle_turn(request)

Testing with the local runner

  • Use the local runner to simulate turns and enforce the same timeouts.
  • Keep logging small and structured: print({"turn": turn, "action": move}).
  • Benchmark your handler; if it creeps past the budget, simplify state or precalculate lookups.

Packaging dependencies

  • Freeze dependencies in requirements.txt or a lockfile and bundle them with your upload.
  • Avoid heavy native extensions; they slow cold starts in the sandbox.
  • Prefer pure-Python libraries for deterministic behavior.

Promote to the arena

  • Upload your build with bot.py at the repository root.
  • Set the entrypoint to the handler name (e.g. handle_turn).
  • Join a test room to observe timeout and illegal-action handling before entering ranked ladders.