onlinecompiler.io

Embed a code editor that runs the code, on any web page

The OnlineCompiler.io widget is an embeddable code editor with an online compiler behind it: readers edit the code, add input and press Run, and it runs on our servers in any of 46 languages. Add it with one script tag, or with an iframe where scripts aren't allowed.

Também em portuguêsTambién en español

This is the editor. Change the code and press Run:

Add it with a script tag

Create a widget key in your dashboard, then add the script and a div for each editor. The code goes in a <pre> inside it, and optional standard input in a <pre data-stdin>:

example.html
<!-- Once per page, or once in your site's layout -->
<script src="https://onlinecompiler.io/widget.js"></script>

<!-- Each editor -->
<div class="runcode" data-key="YOUR_WIDGET_KEY" data-lang="python-3.14" data-theme="light">
<pre>
name = input("What's your name? ")
print(f"Hello, {name}!")
</pre>
<pre data-stdin>Ada</pre>
<a data-credit href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a>
</div>

data-lang takes any compiler id from the language list. data-theme is dark, light or auto, data-readonly locks the code, data-credit="off" hides the "Runs on OnlineCompiler.io" line on Business and above, and the editor renders in Shadow DOM, so your page's CSS and the editor's stay apart. Editors only connect when they scroll near the screen, so a long page of examples stays fast.

Or with an iframe

Many course platforms, site builders and wikis strip script tags but allow an iframe. For those, the embed page holds one editor that fills the frame, with the code and input after the #:

example.html
<iframe src="https://api.onlinecompiler.io/embed/?key=YOUR_WIDGET_KEY&amp;lang=python-3.14&amp;theme=light#code=name%20%3D%20input(%22What's%20your%20name%3F%20%22)%0Aprint(f%22Hello%2C%20%7Bname%7D!%22)&amp;input=Ada"
  title="Runnable Python example" width="100%" height="400" style="border: 0" loading="lazy"></iframe>
<p><a href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a></p>

The embed builder in the docs writes this for you from your code. A key locked to your domain can only be framed by pages on that domain.

Embed a Python interpreter in your website

Set data-lang to python-3.14 and the editor is a Python interpreter readers can type into. input() and sys.stdin read from the Input tab, so programs that take input work as they do in a terminal. Change the numbers in the Input tab and run it again:

import sys, statistics

numbers = [float(n) for n in sys.stdin.read().split()]
print("count:", len(numbers))
print("mean:", statistics.mean(numbers))
print("median:", statistics.median(numbers))

On your own page, it's one script and one div:

python.html
<script src="https://onlinecompiler.io/widget.js"></script>

<div class="runcode" data-key="YOUR_WIDGET_KEY" data-lang="python-3.14">
<pre>
import sys, statistics

numbers = [float(n) for n in sys.stdin.read().split()]
print("count:", len(numbers))
print("mean:", statistics.mean(numbers))
print("median:", statistics.median(numbers))
</pre>
<pre data-stdin>3 1 4 1 5 9 2 6</pre>
<a data-credit href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a>
</div>

Or one iframe, where the page can't take a script:

python.html
<iframe src="https://api.onlinecompiler.io/embed/?key=YOUR_WIDGET_KEY&amp;lang=python-3.14#code=import%20sys%2C%20statistics%0A%0Anumbers%20%3D%20%5Bfloat(n)%20for%20n%20in%20sys.stdin.read().split()%5D%0Aprint(%22count%3A%22%2C%20len(numbers))%0Aprint(%22mean%3A%22%2C%20statistics.mean(numbers))%0Aprint(%22median%3A%22%2C%20statistics.median(numbers))&amp;input=3%201%204%201%205%209%202%206"
  title="Python interpreter" width="100%" height="400" style="border: 0" loading="lazy"></iframe>
<p><a href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a></p>

PyScript and Pyodide are the other common way to put Python in a page, and they work differently:

PyScript and PyodideOnlineCompiler.io widget
Where the code runsIn the reader's browser, on a WebAssembly build of Python the page downloadsOn our servers, in a fresh sandbox for each run
LanguagesPython46, Python included
Inputinput() needs a handler written in JavaScript; Pyodide's default is the browser's prompt() dialogAn Input tab feeds standard input
Cost and limitsFree, and no server runs the code, so speed and memory depend on the reader's deviceFree up to 100,000 runs a month; the same limits for every reader

Pick PyScript or Pyodide when Python should drive the page itself or work without a server. Pick the widget when you want examples in more than one language, input like a terminal, or the same runtime for every reader. Either way, this runs scripts and shows their output; it doesn't host a Python web app for readers to visit. Teachers replacing Trinket embeds can start with the Trinket alternative.

Check answers with the JavaScript API

Each editor fires runcode:run, runcode:result and runcode:error events, and OnlineCompilerWidget.get(div) gives you getCode, setCode, run and reset. This exercise tells the reader whether their answer is right:

exercise.html
<div class="runcode" id="exercise" data-key="YOUR_WIDGET_KEY" data-lang="python-3.14">
<pre># Print the sum of the numbers from 1 to 10
print()</pre>
<a data-credit href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a>
</div>
<p id="verdict"></p>

<script>
  document.getElementById("exercise").addEventListener("runcode:result", (event) => {
    const { exit_code, output } = event.detail;
    const correct = exit_code === 0 && output.trim() === "55";
    document.getElementById("verdict").textContent = correct ? "Correct!" : "Not yet, try again.";
  });
</script>

A hidden template can wrap the reader's code, so they edit only a function body while your test code runs around it. To grade on your server instead, with hidden tests and a score, send the code to the run tests API.

Where people use it

  • Docs sites: setups for Docusaurus, MkDocs, Sphinx, Mintlify and WordPress are in runnable code examples in docs. Docusaurus and MkDocs have free plugins that make any code block marked runnable an editor: see the Docusaurus and MkDocs guides.
  • WordPress: the free plugin adds a Code runner block to the block editor and a shortcode to the classic one; see how to add an online compiler to WordPress.
  • Courses and classrooms: exercises students can run without an account, in the page or in an LMS iframe. Teachers moving off Trinket can start with the Trinket alternative.
  • React apps: render the widget's div from a component, or build your own editor and Run button with a server route that holds the API key, as building an online code editor in React shows.
  • Blogs and tutorials: one editor per example, in any of the 46 languages, from Python and Java to Rust and SQL.

How it compares with other embeddable editors

EditorLanguagesFree runsWorth knowing
OnlineCompiler.io46100,000 a month, shared with the APICode stays in your page's HTML; hidden templates; run and result events; iframe option; one account for the editor, the code execution API and judging
OneCompiler110+Unlimited, free to embedControlled by postMessage (load code, run); output events are not documented
JDoodle114Unlimited embedded IDEs, freeDrag-and-drop editor; classroom features on paid platform plans
CodapiAbout 40 playgroundsOpen-source widget; cloud from $5 a month for 5,000 runs; free to self-hostUnstyled by default; some playgrounds run in the browser
ReplitManyEmbeds are read-onlyEditable embeds ended on 1 August 2022
TrinketClosedNoneShut down on 31 August 2026

If all you need is free runs in as many languages as possible, OneCompiler's and JDoodle's embeds give more of both. Ours fits when the example's code should live in your own page, when you want to check answers or wrap hidden code, or when the same account also runs code from your backend.

Frequently asked questions

How do I embed a code editor in a web page?

Add the script https://onlinecompiler.io/widget.js once, then a div with class runcode, your widget key and a language, with your code in a <pre> inside it. Readers can edit and run the code in any of 46 languages. Where a site strips script tags, paste an iframe of https://api.onlinecompiler.io/embed/ instead.

Is the embeddable code editor free?

Yes, up to 100,000 runs a month across all your editors and API calls, commercial use included, with no credit card. Readers don't need an account.

Does the embedded editor run the code, or only highlight it?

It runs it. Each run goes to our servers, executes in a fresh sandbox with no network access, and the output, errors, exit code, run time and memory come back to the editor.

Can I check whether a reader's answer is right?

Yes. The editor fires a runcode:result event with the output and exit code, so a few lines of JavaScript on your page can compare them with the expected answer. Hidden template code can wrap the reader's code, so they only edit the part that matters.

Can I embed it in an LMS, site builder or wiki that only allows iframes?

Yes, if the platform accepts an iframe. The iframe embed takes the code and input after the # in its URL, so each example is one iframe and the code never reaches a server log.

How do I embed a Python interpreter in my website?

Add the widget script and a div with class runcode and data-lang="python-3.14", or paste an iframe of https://api.onlinecompiler.io/embed/ where scripts aren't allowed. The code runs on our servers in Python 3.14, not in the reader's browser, and input() reads from the editor's Input tab. Free up to 100,000 runs a month.

Is the widget key a secret?

No. Widget keys are meant to sit in public HTML: they only work for the editor, cannot call the REST API, and can be locked to your domain.