C++

Run C++ online

Compile and execute C++17 code instantly with GCC 12 in a secure, isolated sandbox. No setup, no installs. Just write and run.

main.cpp
Output
Click "Run Code" to execute...

About C++

C++ is a high-performance language used in systems programming, game engines, embedded systems, and performance-critical applications. It offers fine-grained memory control, zero-cost abstractions, and the power of the STL.

Our sandbox compiles with GCC 12 and the explicit -std=c++17 language standard.

Sandbox features

  • Secure execution with Docker + gVisor isolation
  • GCC 12 with C++17 standard support
  • Sync/stream: Basic 30s, Pro 60s, Ultra/Mega 150s; async: Ultra 300s, Mega 600s
  • Stdin support for interactive programs
  • REST API for programmatic access
  • No setup or installation required

Use C++ with stateful sessions

Open a session once, then call execute repeatedly. Files written under /home/sandbox persist between calls; each call starts a fresh process, so variables do not carry over. Package install is available for Python (pip) and JavaScript/TypeScript (npm) sessions only.

# 1. Create a session (PRO, ULTRA, or MEGA)
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions \
  -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: sandboxapi.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"language":"cpp","idle_ttl":300}'
# → {"id":"sess_abc","language":"cpp",...}

# 2. Write a file in the session
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions/sess_abc/execute \
  -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: sandboxapi.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"code":"#include <fstream>\nint main(){std::ofstream(\"/home/sandbox/state.txt\")<<42;}"}'

# 3. A later call reads it back: files persist, variables do not
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions/sess_abc/execute \
  -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: sandboxapi.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"code":"#include <fstream>\n#include <iostream>\nint main(){int x;std::ifstream(\"/home/sandbox/state.txt\")>>x;std::cout<<x*2<<std::endl;}"}'
Read the sessions docs →

Need more? Get API access

Integrate secure code execution into your own apps with our REST API. Basic includes 500 requests per RapidAPI subscription period.