Agent Sandbox Registry

agent-sandbox

Decision: AI-generated templates ship a SandboxServer entry point

无中文版

.agents/notes/implemented/feature/2026-09-30-nl-template-server-entrypoint.md

Decision: AI-generated templates ship a SandboxServer entry point

Status: implemented Implemented: 2026-09-30

Problem

abx create "DESCRIPTION" and abx template init "DESCRIPTION" asked the coding agent for two files, Dockerfile and template.yaml, and told it to create nothing else. A deployed sandbox is reached over HTTP(S) (https://<port>-<sandbox_id>.<domain>), so an image with no long-running server has nothing to answer: the generated template could be built and deployed but not used. Every reference template in alibaba-agent-sandbox/awesome-templates (all eleven) instead ships a commands.py that starts the container-side agent_sandbox.server.SandboxServer on port 9000, plus a README. The agent also had no description of that SDK, so it could not have written one.

Decision

  1. The generation prompt asks for a usable template. Required files: Dockerfile, commands.py, template.yaml, and a short README.md. Business code / dependency manifests are allowed when the request needs them; unrelated files are not. Unchanged: no docker, no installs, no secret files.
  2. The server SDK reference is part of the prompt. src/agent_sandbox/agent/template_guide.py holds TEMPLATE_GUIDE, a condensed form of docs/en/design/server-api.md and the awesome-templates conventions: why a server is needed, the Dockerfile rules (python3 + the COPY *.whl / PyPI install pattern, COPY commands.py, EXPOSE 9000, CMD ["python3", "commands.py"]), the agent_sandbox.server API (CapabilityGroup and its default-disabled groups, CommandRegistry, RouteTable.route, ServerResponse, SSEResponse, auth via ABX_SERVER_TOKEN / X-Access-Token), how to run a business web service next to the server, the template.yaml fields (capabilities mapped to the enabled groups, ports including 9000, custom_commands, env names only) and a complete minimal commands.py.
  3. Fail closed on Dockerfile-only output. generate_template_files raises AICodegenError when commands.py is missing, is not valid Python, never imports agent_sandbox.server / calls serve() (or start()), or when the Dockerfile never references commands.py.
  4. Every deliverable travels. CodegenResult.commands_py and CodegenResult.files (workspace-relative, dot-files other than .dockerignore, __pycache__, *.pyc, *.whl excluded) drive the local copy made by template init "DESCRIPTION" and by the create switch, so ./<name>/ contains the whole template. The deploy path already builds the whole workspace directory.
  5. Clarification knows about the server. The research and assessment prompts state that the 9000 server is a fixed practice and must not be asked about; only business interfaces, entry command or ports that cannot be inferred remain valid questions.

Not changed

Alternatives considered

SDK wheel in the image

The Dockerfile snippet (COPY *.whl + PyPI fallback) assumes the builder puts a matching SDK wheel into the context. inject_sdk_wheel used to only build from a source checkout, so an installed abx (PyPI or the PyInstaller binary, which cannot run pip) injected nothing. It now downloads the released wheel of the running version from PyPI (SHA-256 verified, no pip needed) and only then falls back to the Dockerfile's PyPI install. Verified that BuildKit accepts a COPY *.whl that matches nothing, so the fallback path still builds. Covered by TestInjectSdkWheel in tests/test_api/test_docker_builder.py.

Test Strategy

Acceptance criteria

Files changed