unsandbox.com
Anonymous remote code, compile, & execution API for humans & machine learning agents.
Docs 📚 View Pricing →The Groovy examples below require the following 3rd party libraries:
HTTPBuilder or built-in HTTP
Make sure these packages are installed in your environment before running the examples.
Execute code immediately and wait for results. Best for quick scripts and interactive use.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
language |
string | ✓ | Programming language |
code |
string | ✓ | Source code to execute |
env |
object | Environment variables (key-value pairs) | |
network_mode |
string | "zerotrust" or "semitrusted" | |
ttl |
integer | Timeout 1-900s (default: 60) | |
return_artifact |
boolean | Return compiled binary | |
return_wasm_artifact |
boolean | Return WebAssembly binary |
Example (Groovy)
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def apiKey = "YOUR_API_KEY"
def url = new URL("https://api.unsandbox.com/execute")
def connection = url.openConnection()
connection.setRequestMethod("POST")
connection.setDoOutput(true)
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty("Authorization", "Bearer ${apiKey}")
def payload = JsonOutput.toJson([
language: "groovy",
code: 'println "Hello from unsandbox!"'
])
connection.outputStream.write(payload.bytes)
connection.outputStream.close()
def response = connection.inputStream.text
def json = new JsonSlurper().parseText(response)
println json
Response (Success)
{
"success": true,
"stdout": "Hello from unsandbox!\n",
"stderr": "",
"error": null,
"language": "python",
"exit_code": 0
}
Response (Error)
{
"success": false,
"error": "Syntax error in code",
"stderr": "SyntaxError: invalid syntax\n"
}
Submit code for execution and receive a job ID to poll for results. Best for long-running scripts or when you need to decouple submission from execution.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
language |
string | ✓ | Programming language |
code |
string | ✓ | Source code to execute |
env |
object | Environment variables (key-value pairs) | |
network_mode |
string | "zerotrust" or "semitrusted" | |
ttl |
integer | Timeout 1-900s (default: 60) | |
return_artifact |
boolean | Return compiled binary | |
return_wasm_artifact |
boolean | Return WebAssembly binary |
Example (Groovy)
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def apiKey = "YOUR_API_KEY"
def code = '''def factorial(n) {
n <= 1 ? 1 : n * factorial(n - 1)
}
println "Computing factorial..."
println factorial(20)'''
def url = new URL("https://api.unsandbox.com/execute/async")
def connection = url.openConnection()
connection.setRequestMethod("POST")
connection.setDoOutput(true)
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty("Authorization", "Bearer ${apiKey}")
def payload = JsonOutput.toJson([
language: "groovy",
code: code,
ttl: 300
])
connection.outputStream.write(payload.bytes)
connection.outputStream.close()
def response = connection.inputStream.text
def json = new JsonSlurper().parseText(response)
println json
Initial Response
{
"job_id": "job_1234567890_abc",
"status": "pending"
}
Check the status and results of an asynchronous job. Poll this endpoint after submitting a job via /execute/async or /run/async.
URL Parameters
| Parameter | Type | Description |
|---|---|---|
id |
string | Job ID returned from async endpoint |
Example (Groovy)
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def apiKey = "YOUR_API_KEY"
// First create a job to query
def createUrl = new URL("https://api.unsandbox.com/execute/async")
def createConn = createUrl.openConnection()
createConn.setRequestMethod("POST")
createConn.setDoOutput(true)
createConn.setRequestProperty("Content-Type", "application/json")
createConn.setRequestProperty("Authorization", "Bearer ${apiKey}")
def payload = JsonOutput.toJson([
language: "python",
code: "print('test')",
ttl: 60
])
createConn.outputStream.write(payload.bytes)
createConn.outputStream.close()
def createResponse = createConn.inputStream.text
def job = new JsonSlurper().parseText(createResponse)
def jobId = job.job_id
println "Created job: ${jobId}"
Thread.sleep(2000) // Wait for job to be created
// Now get its status
def getUrl = new URL("https://api.unsandbox.com/jobs/${jobId}")
def getConn = getUrl.openConnection()
getConn.setRequestMethod("GET")
getConn.setRequestProperty("Authorization", "Bearer ${apiKey}")
try {
def response = getConn.inputStream.text
def status = new JsonSlurper().parseText(response)
println "Status: ${status.status}"
if (status.result) {
println "Output: ${status.result.stdout}"
}
} catch (Exception e) {
if (getConn.responseCode == 404) {
println "Job not found"
} else {
println "Error: ${e.message}"
}
}
Response (Completed)
{
"job_id": "job_1234567890_abc",
"status": "completed",
"result": {
"success": true,
"stdout": "Hello from unsandbox!\n",
"stderr": "",
"error": null,
"language": "python",
"exit_code": 0
}
}
Possible Status Values
pending- Job queued, waiting to executerunning- Job currently executingcompleted- Job finished (check result field)timeout- Job exceeded TTL limitcancelled- Job was cancelled via DELETE
List all active (pending or running) jobs for your API key. Useful for monitoring multiple async executions.
Example (Groovy)
import groovy.json.JsonSlurper
def apiKey = "YOUR_API_KEY"
def url = new URL("https://api.unsandbox.com/jobs")
def connection = url.openConnection()
connection.setRequestMethod("GET")
connection.setRequestProperty("Authorization", "Bearer ${apiKey}")
def response = connection.inputStream.text
def json = new JsonSlurper().parseText(response)
println json
Response
{
"jobs": [
{
"job_id": "job_1234567890_abc",
"status": "running",
"language": "python",
"submitted_at": "2024-01-15T10:30:00Z"
},
{
"job_id": "job_0987654321_xyz",
"status": "pending",
"language": "go",
"submitted_at": "2024-01-15T10:29:45Z"
}
]
}
Cancel a pending or running job. If the job is already executing, it will be terminated and partial output returned.
URL Parameters
| Parameter | Type | Description |
|---|---|---|
id |
string | Job ID to cancel |
Example (Groovy)
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def apiKey = "YOUR_API_KEY"
// First create a job to delete
def createUrl = new URL("https://api.unsandbox.com/execute/async")
def createConn = createUrl.openConnection()
createConn.setRequestMethod("POST")
createConn.setDoOutput(true)
createConn.setRequestProperty("Content-Type", "application/json")
createConn.setRequestProperty("Authorization", "Bearer ${apiKey}")
def payload = JsonOutput.toJson([
language: "python",
code: "print('test')",
ttl: 60
])
createConn.outputStream.write(payload.bytes)
createConn.outputStream.close()
def createResponse = createConn.inputStream.text
def job = new JsonSlurper().parseText(createResponse)
def jobId = job.job_id
println "Created job: ${jobId}"
// Now delete it
def deleteUrl = new URL("https://api.unsandbox.com/jobs/${jobId}")
def deleteConn = deleteUrl.openConnection()
deleteConn.setRequestMethod("DELETE")
deleteConn.setRequestProperty("Authorization", "Bearer ${apiKey}")
try {
def response = deleteConn.inputStream.text
def json = new JsonSlurper().parseText(response)
println "Deleted: ${json}"
} catch (Exception e) {
if (deleteConn.responseCode == 404) {
println "Job not found (may have already completed)"
} else {
println "Error: ${e.message}"
}
}
Response
{
"message": "Job cancelled",
"job_id": "job_1234567890_abc",
"result": {
"success": false,
"stdout": "Partial output before cancel...",
"stderr": "",
"error": "Job cancelled by user",
"exit_code": -1
}
}
Execute code with automatic language detection via shebang. Send raw code as the request body with Content-Type: text/plain.
Request
- Content-Type:
text/plain - Body: Raw code with shebang (e.g.,
#!/usr/bin/env python3)
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
env |
string | URL-encoded JSON object with environment variables | |
network_mode |
string | "zerotrust" or "semitrusted" | |
ttl |
integer | Timeout 1-900s (default: 60) | |
return_artifact |
boolean | Return compiled binary | |
return_wasm_artifact |
boolean | Return WebAssembly binary |
Example (Groovy)
def apiKey = "YOUR_API_KEY"
def url = new URL("https://api.unsandbox.com/run")
def connection = url.openConnection()
connection.setRequestMethod("POST")
connection.setDoOutput(true)
connection.setRequestProperty("Content-Type", "text/plain")
connection.setRequestProperty("Authorization", "Bearer ${apiKey}")
def code = 'println "Language auto-detected!"'
connection.outputStream.write(code.bytes)
connection.outputStream.close()
def response = connection.inputStream.text
println response
Response
{
"success": true,
"stdout": "Language auto-detected!\n",
"stderr": "",
"error": null,
"detected_language": "python",
"exit_code": 0
}
Submit code with automatic language detection and receive a job ID. Combines the convenience of /run with the flexibility of async execution.
Request
- Content-Type:
text/plain - Body: Raw code with shebang (e.g.,
#!/usr/bin/env ruby)
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
env |
string | URL-encoded JSON object with environment variables | |
network_mode |
string | "zerotrust" or "semitrusted" | |
ttl |
integer | Timeout 1-900s (default: 60) | |
return_artifact |
boolean | Return compiled binary | |
return_wasm_artifact |
boolean | Return WebAssembly binary |
Example (Groovy)
import groovy.json.JsonSlurper
def apiKey = "YOUR_API_KEY"
def code = '''#!/usr/bin/env ruby
puts "Running async with auto-detect!" '''
def url = new URL("https://api.unsandbox.com/run/async")
def connection = url.openConnection()
connection.setRequestMethod("POST")
connection.setDoOutput(true)
connection.setRequestProperty("Content-Type", "text/plain")
connection.setRequestProperty("Authorization", "Bearer ${apiKey}")
connection.outputStream.write(code.bytes)
connection.outputStream.close()
def response = connection.inputStream.text
def job = new JsonSlurper().parseText(response)
def jobId = job.job_id
println "Job submitted: ${jobId}"
Thread.sleep(2000) // Wait for job to be created
// Poll for results
while (true) {
def statusUrl = new URL("https://api.unsandbox.com/jobs/${jobId}")
def statusConn = statusUrl.openConnection()
statusConn.setRequestProperty("Authorization", "Bearer ${apiKey}")
try {
def statusResponse = statusConn.inputStream.text
def status = new JsonSlurper().parseText(statusResponse)
if (status.status == "completed") {
def result = status.result
println "Detected: ${result.detected_language}"
if (result.exit_code == 0) {
println "Output: ${result.stdout}"
}
break
} else if (status.status in ["timeout", "cancelled"]) {
println "Job ${status.status}"
break
}
} catch (Exception e) {
println "Error checking status: ${e.message}"
break
}
Thread.sleep(1000)
}
Initial Response
{
"job_id": "job_1234567890_abc",
"status": "pending"
}
Job Result (via GET /jobs/{id})
{
"job_id": "job_1234567890_abc",
"status": "completed",
"result": {
"success": true,
"stdout": "Running async with auto-detect!\n",
"stderr": "",
"error": null,
"detected_language": "ruby",
"exit_code": 0
}
}