quick_run() method provides a fast and secure way to execute code directly within your Python application. It supports ten popular runtimes, including Python, Java, C++, Node.js, and more.
Before calling
quick_run(), you must first connect to the sandbox using either await create() or await from_snippet(). The sandbox must be active before you can execute any code.Supported Languages
The following programming languages are supported by thequick_run() method.
C / C++
Java
Python
Node.js
SQLite / MySQL
Go
Rust
.NET (C#)
Method Signature
async quick_run(runtime: Literal['C', 'C++', 'Java', 'Python', 'Node.js', 'SQLite', 'MySQL', 'Go', 'Rust', '.NET'], source_code: str, stdin: Optional[str] = None, expected_output: Optional[str] = None, additional_files_as_zip: Optional[str] = None) -> DecodedRunResult
Description:Executes code using the DSA execution API and returns the results. This method provides a simple way to execute code in various languages without needing to set up a full sandbox container.
Method Parameters
Thequick_run() method takes a set of parameters that define how your code will execute. Some are required, while others allow input, validation, or additional file support.
Required Parameters
| Parameter | Type | Description |
|---|---|---|
runtime | str | The programming language to execute (must match one of the supported runtimes above). |
source_code | str | The source code to execute inside the sandbox. Use triple quotes (""") or backticks for multi-line strings. |
Optional Parameters
| Parameter | Type | Description |
|---|---|---|
stdin | str | Input data passed to the programβs standard input. |
expected_output | str | Expected output for validation purposes. |
additional_files_as_zip | str | Base64URL-encoded ZIP file containing extra files (e.g., database schema or dependencies). |
Execution Results
Thequick_run() method returns a DecodedRunResult object containing detailed execution results: status, output, timing, and resource usage.
| Field | Description |
|---|---|
run_status | Final execution result (RunStatus enum). Use .value to get the string value. Possible values: "successful", "compilation-error", "time-limit-exceeded", "wrong-answer", "non-zero-exit-code", "died-sigsev", "died-sigfpe", "died-sigabrt", "internal-isolate-error", "unknown". |
program_run_data | Object holding detailed execution data like stdout, stderr, CPU time, and memory usage. Returns None if execution hasnβt finished. |
program_run_data.stdout | Programβs standard output (already decoded by the SDK, not Base64URL). |
program_run_data.stderr | Programβs error output (already decoded by the SDK, not Base64URL). |
program_run_data.cpu_time_used_in_milliseconds | CPU time consumed during execution (milliseconds). |
program_run_data.wall_time_used_in_milliseconds | Real (wall-clock) time elapsed (milliseconds). |
program_run_data.memory_used_in_kilobyte | Memory used during execution (kilobytes). |
program_run_data.exit_code | Programβs exit code (0 indicates success). |
program_run_data.exit_signal | Termination signal if the process was killed, or 0 otherwise. |
compiler_output_after_compilation | Compiler output (for compiled languages). Already decoded by SDK; returns None for interpreted languages. |
finished_at | ISO 8601 UTC timestamp when execution finished (e.g., "2025-11-06T08:14:10.127Z"). |
Validation (if you provided expected_output)
If you supplied an expected_output when running your code, QuickRun automatically compares the actual output with your expected value. The comparison result is reflected in the run_status field:
- If the output matches:
run_status.valuewill be"successful" - If the output doesnβt match:
run_status.valuewill be"wrong-answer" - If thereβs a compilation error:
run_status.valuewill be"compilation-error" - If thereβs a runtime error:
run_status.valuewill be"non-zero-exit-code"or another error status
How to Use quick_run()
Below are examples showing how to usequick_run() in Python.
Error Handling
Even well-written code can fail. Thequick_run() method provides clear and structured feedback to help you identify and debug issues efficiently.Common failure types include compilation errors, runtime exceptions, and timeouts.
Each is explained below with example usage.
Compilation Errors
Compilation Errors
Compilation errors occur when the source code cannot be compiled, typically due to syntax issues or missing elements. The
run_status.value will be "compilation-error", and the compiler output can be accessed through compiler_output_after_compilation.Runtime Errors
Runtime Errors
Runtime errors happen when the code compiles successfully but fails during execution, for example, dividing by zero or accessing invalid memory. In such cases,
run_status.value will be "non-zero-exit-code", and the error details are available in program_run_data.stderr.Timeout Errors
Timeout Errors
Timeout errors occur when a program runs beyond the allowed execution time. In such cases, the
run_status.value will be "time-limit-exceeded".Best Practices
- Connect to the sandbox first: Always call
await create()orawait from_snippet()before usingquick_run(). - Always check
run_statusfirst: Before reading output, confirm the code executed successfully (run_status.value == "successful"). - Ensure
program_run_datais notNone: Verify that the result object includesprogram_run_databefore accessing its properties. - Output is automatically decoded: The SDK automatically decodes
stdout,stderr, andcompiler_output_after_compilation. You can use them directly without additional decoding. - Use
expected_outputfor automated validation: If the output matches your expected value,run_status.valuewill be"successful", otherwise it will be"wrong-answer". - Handle errors gracefully: Check
run_status.valueand readstderrto display meaningful error messages. - Validate user input: Always validate and sanitize user-submitted code before execution to ensure safety and reliability.
Performance Tips
- Typical code execution time: 1β3 seconds
- Compiled languages (C++, Java, Rust) may take slightly longer due to compilation overhead.
- Interpreted languages (Python, Node.js) generally start faster.
- Database runtimes (SQLite, MySQL) depend on query complexity and data size.
Frequently Asked Questions
How long does code execution take?
How long does code execution take?
Code execution typically completes within 1β3 seconds, depending on the language,
code complexity, and whether compilation is required.
Interpreted languages like Python or Node.js tend to execute faster, while compiled languages such as Java or Rust may take slightly longer.
Interpreted languages like Python or Node.js tend to execute faster, while compiled languages such as Java or Rust may take slightly longer.
What if my code needs external files?
What if my code needs external files?
You can include additional files by encoding them as a Base64 ZIP and passing
them through the
This allows your program to access dependencies, data files, or assets during execution.
additional_files_as_zip parameter.This allows your program to access dependencies, data files, or assets during execution.
Can I run code that reads from files?
Can I run code that reads from files?
Yes. Your program can read from files provided through
or you can simulate user input using the
additional_files_as_zip,or you can simulate user input using the
stdin parameter for simpler text-based input.What happens if my code runs forever?
What happens if my code runs forever?
Each code execution has a time limit to prevent infinite loops or unresponsive code.
If your program exceeds this limit, itβs automatically stopped and marked as
If your program exceeds this limit, itβs automatically stopped and marked as
time-limit-exceeded in the result object.Is the execution environment safe?
Is the execution environment safe?
Absolutely. All code runs inside a secure, isolated sandbox with strict resource and
permission controls. This ensures your application and data remain safe from malicious or runaway code.
