Skip to content

sharryy/code-arena

Repository files navigation

Code Arena

A little playground I built to show off docker-sandbox — a PHP package for running untrusted code safely inside Docker.

Paste some PHP, Python or Node, hit Run, and it executes in a throwaway container that has no network, runs as a non-root user, can't write to its own filesystem, and gets killed if it runs too long. There's also a little HackerRank-style section where your solution is graded against hidden tests.

What's in it

  • Playground — write code, run it, see the output (plus the exit code and how long it took). The "try to break out" buttons run deliberately nasty snippets — an infinite loop, a network call, a write to disk — so you can watch the sandbox shut each one down.
  • Challenges — solve a problem in any of the three languages; Submit runs it against the full hidden test suite and shows you which cases passed.

Running it locally

You'll need PHP 8.3+, Composer, Node, and a Docker daemon (Docker Desktop, Colima, Lima — whatever you've got).

composer install
npm install && npm run build
cp .env.example .env
php artisan key:generate
php artisan migrate
php artisan serve

Then open http://localhost:8000.

If your Docker socket isn't at the default path (Colima, for example), point the app straight at it in .env:

DOCKER_SOCKET=/Users/you/.colima/default/docker.sock

How it works

Every run goes through the package — that's the whole point:

$result = (new Sandbox)->php('<?php echo 2 + 2;');

$result->output();      // "4"
$result->exitCode();    // 0
$result->duration();    // seconds

For challenges, your solve(...) function gets wrapped with a tiny harness that runs every test case through it and compares the JSON results — so the exact same grading works across PHP, Python and Node.

Tests

php artisan test

Heads up: these actually start containers and run real code, so Docker needs to be running.


Built with Laravel, Livewire, Tailwind and CodeMirror.

About

A code execution playground demoing the docker-sandbox PHP package — runs untrusted PHP/Python/Node safely in Docker.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors