Skip to content
Sandworld

Search the docs and guides

    Open this page as Markdown
    On this page

      Hosted agents

      Test your agent without deploying it. Upload its code as a zip, or give a public git URL, and say how to start it. Sandworld starts it in an isolated E2B sandbox, waits for its server, then plays Bench Hard, Bench v1 or any world against it, with the same verifiers, scorecard and CI support as any other run. Hosted runs are on the Pro and Team plans; on every plan you can also deploy the agent yourself and point a run at its endpoint.

      Hosted runs are being switched on. Until they are, the option reads “not available yet” in the app and the API answers 503 hosted_unavailable.

      How it works

      1. Your code is checked (paths, symlinks, sizes) and copied into a fresh sandbox. A git URL is cloned there.
      2. Your start command runs in the code's folder with bash, for example pip install -r requirements.txt && python server.py. Your environment variables (model keys) are passed to it, along with PORT and SANDWORLD_TOKEN.
      3. Sandworld waits for something to answer on the port (up to 4 minutes), then sends one test request. Meanwhile the run shows Starting your agent and what it's doing. If your server exits, never answers, or fails the test (a wrong key or model name, say), the run ends without playing, doesn't count, and its error shows your server's last output.
      4. Every episode then calls your server, turn by turn, exactly like a run against your own endpoint.
      5. The sandbox is stopped when the run finishes, fails or runs out of time.

      The contract

      Your server speaks the OpenAI Chat Completions API, the same contract as “Your agent's endpoint”. On each turn Sandworld sends the whole conversation so far and the app's tools to <path>/chat/completions (path /v1 by default), and your server answers with the agent's next message: tool calls to make, or a final reply when it's done. Sandworld runs the tools, adds their results, and calls again. Your agent can do anything to decide: call one model or several, plan, search, keep notes.

      HTTP
      POST <path>/chat/completions
      Authorization: Bearer <SANDWORLD_TOKEN>
      Content-Type: application/json
      
      {
        "model": "my-agent",
        "messages": [
          {"role": "system", "content": "You are an AI agent operating the Quickbasket app… <policy>…</policy>"},
          {"role": "user", "content": "My order QB-10388 was missing the penne. Can you sort it out?"},
          {"role": "assistant", "content": null, "tool_calls": [{"id": "call_1", "type": "function",
            "function": {"name": "get_order", "arguments": "{\"order_id\": \"QB-10388\"}"}}]},
          {"role": "tool", "tool_call_id": "call_1", "content": "{\"id\": \"QB-10388\", …}"}
        ],
        "tools": [{"type": "function", "function": {"name": "get_order", "description": "…", "parameters": {…}}}],
        "tool_choice": "auto",
        "seed": 1
      }
      JSON
      {
        "choices": [{
          "index": 0,
          "finish_reason": "tool_calls",
          "message": {
            "role": "assistant",
            "content": null,
            "tool_calls": [{"id": "call_2", "type": "function",
              "function": {"name": "report_item_issue", "arguments": "{\"order_id\": \"QB-10388\", …}"}}]
          }
        }],
        "usage": {"prompt_tokens": 1830, "completion_tokens": 41}
      }
      • Listen on 0.0.0.0 at the port you give (also in $PORT). Any answer on the port other than HTTP 502 tells Sandworld the server is up.
      • Every request carries Authorization: Bearer $SANDWORLD_TOKEN, a random token made for this run. The sandbox's URL already refuses anyone but Sandworld; checking the token as well is good practice.
      • Answer within 10 minutes a turn. Up to 4 episodes play at once, so handle concurrent requests (a threading server is enough).
      • The agent id is compat:<name>; the name is sent as model and shown on the run.

      A minimal example in Python

      Two files in a folder. Zip the folder, or push it to a public repository. Start command: pip install -r requirements.txt && python server.py. Environment: OPENAI_API_KEY.

      requirements.txt
      openai>=1.40
      Python
      # server.py: a minimal agent behind Sandworld's endpoint contract.
      # Sandworld sends the conversation and the app's tools; the agent answers with
      # its next message (tool calls, or a final reply). Here the "agent" adds one rule
      # to the prompt and asks OpenAI; put your own planning, memory or tools here.
      import json
      import os
      from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
      
      from openai import OpenAI
      
      client = OpenAI()  # reads OPENAI_API_KEY, which you pass as an environment variable
      MODEL = os.environ.get("AGENT_MODEL", "gpt-5-mini")
      TOKEN = os.environ.get("SANDWORLD_TOKEN", "")
      RULE = "Before you change anything, look the record up and check it against the policy."
      
      
      class Agent(BaseHTTPRequestHandler):
          def do_POST(self):
              if self.path.rstrip("/") != "/v1/chat/completions":
                  return self.send_error(404)
              if TOKEN and self.headers.get("authorization") != f"Bearer {TOKEN}":
                  return self.send_error(401)
              body = json.loads(self.rfile.read(int(self.headers["content-length"])))
              messages = body["messages"]
              messages[0]["content"] += "\n\n" + RULE
              reply = client.chat.completions.create(
                  model=MODEL, messages=messages, tools=body.get("tools"), tool_choice="auto")
              out = json.dumps(reply.model_dump(exclude_none=True)).encode()
              self.send_response(200)
              self.send_header("content-type", "application/json")
              self.send_header("content-length", str(len(out)))
              self.end_headers()
              self.wfile.write(out)
      
          def do_GET(self):  # a health check: anything but 502 tells Sandworld you're up
              self.send_response(200)
              self.end_headers()
      
      
      port = int(os.environ.get("PORT", "8000"))
      ThreadingHTTPServer(("0.0.0.0", port), Agent).serve_forever()

      Start a run

      In the app: under Evals, choose Hosted agent as the agent, then the zip or git URL, the start command, port and variables. The run page opens at once and follows your agent as it starts (usually under a minute, longer when it installs a lot).

      From CI with sw eval (see Run from CI): give it the folder or zip, the start command and the variables to pass. It zips a folder for you (leaving out .git, node_modules and virtualenvs), uploads it, prints each start-up step, then the run's progress. Values for --hosted-env are read from the job's environment, never typed on the command line.

      Shell
      sw eval --suite hard --model my-agent --hosted-zip ./agent \
        --start-cmd "pip install -r requirements.txt && python server.py" \
        --hosted-env OPENAI_API_KEY --min-pass 0.4 --junit sandworld-junit.xml
      
      # or from a public repository:  --hosted-git https://github.com/you/agent --git-ref main
      # other options:                 --port 8000  --api-path /v1

      From the API (an API key with the evals scope): upload the zip, then start the run with its id. The start request answers at once with "phase": "starting"; poll GET /api/v1/runs/{id}, whose phase_detail says what the agent is doing until the run plays.

      Shell
      API=https://sandworld.dev/api/v1
      
      # 1 · upload the zip (up to 25 MB); the id is good for 30 minutes
      UPLOAD=$(curl -s -X POST $API/runs/uploads \
        -H "Authorization: Bearer $SANDWORLD_API_KEY" \
        -H "content-type: application/zip" --data-binary @agent.zip | jq -r .id)
      
      # 2 · start Bench Hard against it (or "git": "https://github.com/you/agent" instead of "upload")
      curl -s -X POST $API/runs \
        -H "Authorization: Bearer $SANDWORLD_API_KEY" -H "content-type: application/json" \
        -d '{"suite": "hard", "agent": "compat:my-agent", "seeds": [1],
             "hosted": {"upload": "'$UPLOAD'", "start": "pip install -r requirements.txt && python server.py",
                        "port": 8000, "path": "/v1",
                        "env": {"OPENAI_API_KEY": "'$OPENAI_API_KEY'"}}}'

      hosted takes upload or git (with an optional ref, a branch or tag), start, port (default 8000), path (default /v1) and env. The start request can answer plan_hosted (402), upload_not_found or unsafe_git_url (400), and hosted_busy or hosted_unavailable (503). A start-up that fails afterwards ends the run with status failed and an error that begins “Your hosted agent didn't start” and includes your server's last output; such runs don't count towards your plan.

      Limits

      CodeA zip up to 25 MB, 5,000 files and 250 MB unpacked, or a public https git repository (shallow clone). One top-level folder is fine. No symlinks, absolute paths or ...
      Start-up4 minutes to install, start and answer the test request.
      Run timeThe run's own deadline (every episode's limit, as on any run), up to 50 minutes once your agent is up. Waiting for a free slot doesn't count. Episodes still playing when time is up end with an error and are graded as they stand.
      EnvironmentUp to 20 variables. PORT, SANDWORLD_TOKEN and names starting with SANDWORLD_ or E2B_ are set by Sandworld or the sandbox.
      SandboxE2B's default image: Debian with Python 3, Node.js, git and build tools. Your server can reach the internet (to call its model).
      PlansPro and Team. Hosted runs count as runs and follow your plan's seeds and runs at once.

      Security

      • Your code never runs on Sandworld's servers. It runs in its own E2B sandbox (a Firecracker microVM), which is stopped when the run ends, fails or runs out of time. After a restart of Sandworld's server, every sandbox left behind is stopped.
      • Your environment variables are handled like any key you give Sandworld: kept in memory for this run only, passed to your process when it starts, never stored, logged or sent back, and removed from every error message.
      • The sandbox's address accepts only Sandworld's requests (E2B's private traffic token), and each request also carries SANDWORLD_TOKEN. The run records which sandbox it used (e2b://<id>), never its address or tokens.
      • An uploaded zip is kept in memory until its run starts (30 minutes at most), for your workspace only.
      • A git URL must be public https on a public host; it is cloned inside the sandbox. Private repositories aren't supported: upload a zip instead.

      Try it in the browser first

      To get a feel for the loop without any server, the sandbox's Write an agent tab runs a Python agent in your browser against any task, with your own model key.