A code editor API should distinguish editing from execution. Saving source text is not the same operation as running it, and each operation has different limits, permissions, and failure modes. Keeping them separate makes the contract easier to secure and evolve.
Specify the request
A run request should name the language using a server-approved identifier, include source text, and optionally reference a previously created project. Validate source length and reject unsupported languages before scheduling work. Do not accept an arbitrary runtime image, executable, or compiler flag from the browser. If input files are supported, define their names, sizes, and encoding rules.
The response should model state rather than imply that every request completes immediately. A synchronous endpoint can return bounded stdout, stderr, exit code, and duration. An asynchronous contract can return a job ID and status URL, followed by explicit queued, running, succeeded, failed, timed-out, or cancelled states. Document what each status means.
Make limits visible
Enforce time, memory, CPU, output, and concurrency limits on the server. Return stable error codes for invalid input, quota exhaustion, unsupported runtime, and infrastructure failure. Never expose container paths, internal host details, or raw stack traces. Include a request ID for support and tracing.
Version the contract when semantics change, and generate client types from the same schema where practical. Test malformed payloads, large source, timeouts, output truncation, and authorization. A precise contract lets the interface explain what happened without guessing.
Specify what a completed run means
An editor can display an HTTP 200 response that describes a program with a nonzero exit code. The HTTP request succeeded at handing work to the execution service, and the program failed. Keep HTTP validation and authorization errors separate from job outcomes such as compile error, timeout, and completed execution. Include limits or truncation metadata where the client needs it to explain missing output.
Publish the transport contract with OpenAPI 3.1 so readers can inspect required fields and documented response variants. A discriminator or explicitly documented outcome field helps a client decide whether to render output, show a compile error, or ask a user to sign in. Put runtime limits under server control and test each terminal state with a known fixture. OpenAPI 3.1.1 specification
Worked example
This is a sample request shape, not a promise about a deployed endpoint. Document input limits and authentication; distinguish an HTTP transport failure from a successful execution response containing a nonzero process exit code.
json{ "language": "javascript", "source": "console.log(2 + 3)", "stdin": "" }




Community
Discussion
Loading comments…