Run Python code
curl --request POST \
--url https://app.dumplingai.com/api/v1/run-python-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"code": "def main():\n return 'hi'"
}
EOFimport requests
url = "https://app.dumplingai.com/api/v1/run-python-code"
payload = { "code": "def main():
return 'hi'" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: 'def main():\n return \'hi\''})
};
fetch('https://app.dumplingai.com/api/v1/run-python-code', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.dumplingai.com/api/v1/run-python-code",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'def main():
return \'hi\''
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.dumplingai.com/api/v1/run-python-code"
payload := strings.NewReader("{\n \"code\": \"def main():\\n return 'hi'\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.dumplingai.com/api/v1/run-python-code")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"def main():\\n return 'hi'\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.dumplingai.com/api/v1/run-python-code")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"def main():\\n return 'hi'\"\n}"
response = http.request(request)
puts response.read_body{
"logs": {
"stdout": [
"<string>"
],
"stderr": [
"<string>"
]
}
}{
"error": "<string>"
}{
"error": "<string>"
}Developer Tools
Run Python Code
Execute sandboxed Python code and return stdout, stderr, and logs.
POST
/
api
/
v1
/
run-python-code
Run Python code
curl --request POST \
--url https://app.dumplingai.com/api/v1/run-python-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"code": "def main():\n return 'hi'"
}
EOFimport requests
url = "https://app.dumplingai.com/api/v1/run-python-code"
payload = { "code": "def main():
return 'hi'" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: 'def main():\n return \'hi\''})
};
fetch('https://app.dumplingai.com/api/v1/run-python-code', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.dumplingai.com/api/v1/run-python-code",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'def main():
return \'hi\''
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.dumplingai.com/api/v1/run-python-code"
payload := strings.NewReader("{\n \"code\": \"def main():\\n return 'hi'\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.dumplingai.com/api/v1/run-python-code")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"def main():\\n return 'hi'\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.dumplingai.com/api/v1/run-python-code")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"def main():\\n return 'hi'\"\n}"
response = http.request(request)
puts response.read_body{
"logs": {
"stdout": [
"<string>"
],
"stderr": [
"<string>"
]
}
}{
"error": "<string>"
}{
"error": "<string>"
}Description
This endpoint allows you to run Python code in a secure sandbox environment. The code is executed using a secure code interpreter and returns both stdout and stderr logs.Endpoint
POST https://app.dumplingai.com/api/v1/run-python-code
Headers
- Content-Type:
application/json - Authorization: Bearer
<API_KEY>(required)
Request Body
{
"commands": "string", // Optional. Install pip packages before code execution e.g. pip install pandas
"code": "string", // Required. The Python code to be executed
"parseJson": boolean, // Optional. Whether to parse stdout/stderr as JSON
}
Responses
Success (200)
Returns the output logs from the executed Python code.{
"logs": {
"stdout": string[] | any, // Array of stdout messages or parsed JSON
"stderr": string[] | any // Array of stderr messages or parsed JSON
}
}
- Content-Type: application/json
- X-RateLimit-Limit: The rate limit for the user.
- X-RateLimit-Remaining: The remaining number of requests for the user.
Bad Request (400)
Returned if the request is missing required parameters.{
"error": "code parameter is required"
}
Internal Server Error (500)
Returned if there’s an error during code execution.{
"error": {
"name": "string",
"value": "string",
"traceback": "string"
}
}
Example Request
curl -X POST https://app.dumplingai.com/api/v1/run-python-code \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"commands": "pip install pandas",
"code": "import pandas as pd\ndata = {\"name\": [\"John\", \"Jane\"], \"age\": [30, 25]}\ndf = pd.DataFrame(data)\nprint(df.to_json())",
"parseJson": true
}'
Example Response
{
"logs": {
"stdout": {
"name": { "0": "John", "1": "Jane" },
"age": { "0": 30, "1": 25 }
},
"stderr": []
}
}
Notes
- This endpoint uses 50 credits per request.
- Code execution timeout is set to 10 seconds
- The code is executed in a secure sandbox environment
- When
parseJsonis true, the system will attempt to parse stdout and stderr as JSON - You can install Python packages by using the
commandsparameter e.g.pip install pandas
Rate Limiting
Rate limit headers (X-RateLimit-Limit and X-RateLimit-Remaining) are included in the response to indicate the user’s current rate limit status.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Request payload for sandboxed code execution.
Source code to execute inside the sandbox.
Shell commands to run before executing the code.
Attempt to parse stdout/stderr as JSON arrays.
Optional identifier describing where the API request originated.
Available options:
API, WEB, MAKE_DOT_COM, ZAPIER, N8N, PLAYGROUND, DEFAULT_AUTOMATION, AGENT_PREVIEW, AGENT_LIVE, AUTOPILOT, STUDIO Response
Execution results returned.
Show child attributes
Show child attributes