Compile and execute Java code instantly in a secure, isolated sandbox. No JDK setup, no installs — just write and run.
Java is the enterprise standard for building robust, cross-platform applications. With the JVM ecosystem, strong typing, and decades of battle-tested libraries, Java powers everything from Android apps to large-scale distributed systems.
Our sandbox runs Java 21 (LTS) with full JDK support.
Open a session once, then call execute repeatedly. Files and installed packages persist between runs, which is ideal for code interpreters and iterative agents.
# 1. Create a session curl -X POST https://api.sandboxapi.dev/v1/sessions \ -H "X-RapidAPI-Key: $KEY" \ -d '{"language":"java","idle_ttl":300}' # → {"id":"sess_abc","language":"java",...} # 2. Execute — first call curl -X POST https://api.sandboxapi.dev/v1/sessions/sess_abc/execute \ -H "X-RapidAPI-Key: $KEY" \ -d '{"code":"int x = 42; System.out.println(x);"}' # 3. Execute again — state carries over curl -X POST https://api.sandboxapi.dev/v1/sessions/sess_abc/execute \ -H "X-RapidAPI-Key: $KEY" \ -d '{"code":"// Note: Java is compiled — sessions persist files, not REPL state"}'
Note: Java is a compiled language. Sessions persist installed packages and files on disk, but variable state does not carry between calls. Write intermediate state to disk when you need continuity.
Integrate secure code execution into your own apps with our REST API. Free tier includes 500 executions per month.
Get API Key on RapidAPI