2 stable releases
new 1.1.0 | Jan 6, 2025 |
---|---|
1.0.0 | Dec 31, 2024 |
#11 in #competitive-programming
244 downloads per month
22KB
554 lines
Code Executor
A library designed for the backend of competitive programming platforms
Built-in Language
- C++
- Rust
- Java
- Python
Usage
- Run C++ hello world and get output
use code_executor::CPP_RUNNER;
fn main() {
let output = CPP_RUNNER
.run(
r#"
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << "Hello World";
}
"#,
"input.txt",
);
println!("{:?}", output);
}
- Define custom runner
let cpp_runner = Runner {
main_file: "main.cpp",
compiler_args: Some(CommandArgs {
binary: "g++",
args: &["-o", "main", "main.cpp"],
}),
sandbox_config: sandbox::Config {
scmp_black_list: &[
RlimitConfig {
resource: Resource::RLIMIT_STACK,
soft_limit: 1024 * 1024 * 1024 * 1024,
hard_limit: 1024 * 1024 * 1024 * 1024,
},
RlimitConfig {
resource: Resource::RLIMIT_AS,
soft_limit: 1024 * 1024 * 1024 * 1024,
hard_limit: 1024 * 1024 * 1024 * 1024,
},
RlimitConfig {
resource: Resource::RLIMIT_CPU,
soft_limit: 60,
hard_limit: 90,
},
RlimitConfig {
resource: Resource::RLIMIT_FSIZE,
soft_limit: 1024,
hard_limit: 1024,
},
],
rlimit_configs: &["fork", "vfork"],
time_limit: Duration::from_secs(2),
args: CommandArgs {
binary: "./main",
args: &[],
},
},
};
Dependencies
~3.5MB
~72K SLoC