Skip to content

Commit 06f8727

Browse files
authored
refactor: rename sandbox.command.execute to sandbox.command.run (#229)
* refactor: rename sandbox.command.execute to sandbox.command.run Rename RPC method from sandbox.command.execute to sandbox.command.run for better consistency with other API methods. This includes: - Updating method name in RPC handlers - Renaming SandboxCommandExecuteParams to SandboxCommandRunParams - Updating documentation and examples - Updating Python and Rust SDK implementations * refactor: update engine handle naming and platform status - Update platform support badges in README (Linux working, Windows WIP) - Rename engine_handle to _engine_handle to fix unused variable warnings - Add cfg attributes for conditional compilation in repl_timer.rs * chore(release): bump version to 0.2.2 Update version from 0.2.1 to 0.2.2 in: - Cargo.toml workspace version - Internal crate dependencies - Installation script default version
1 parent 87f6e82 commit 06f8727

File tree

14 files changed

+71
-68
lines changed

14 files changed

+71
-68
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ resolver = "2"
1212
[workspace.package]
1313
authors = ["Team MicroSandbox <[email protected]>"]
1414
repository = "https://github.com/microsandbox/microsandbox"
15-
version = "0.2.1"
15+
version = "0.2.2"
1616
license = "Apache-2.0"
1717
edition = "2021"
1818

@@ -47,9 +47,9 @@ rand = "0.9"
4747
reqwest = { version = "0.12", features = ["stream", "json"] }
4848
reqwest-middleware = "0.3" # Cannot upgrade to 0.4 due to https://github.com/TrueLayer/reqwest-middleware/issues/204
4949
reqwest-retry = "0.6" # Cannot upgrade to 0.7 due to https://github.com/TrueLayer/reqwest-middleware/issues/204
50-
microsandbox-utils = { version = "0.2.1", path = "./microsandbox-utils" }
51-
microsandbox-core = { version = "0.2.1", path = "./microsandbox-core" }
52-
microsandbox-server = { version = "0.2.1", path = "./microsandbox-server" }
50+
microsandbox-utils = { version = "0.2.2", path = "./microsandbox-utils" }
51+
microsandbox-core = { version = "0.2.2", path = "./microsandbox-core" }
52+
microsandbox-server = { version = "0.2.2", path = "./microsandbox-server" }
5353
multihash = "0.19"
5454
multihash-codetable = "0.1"
5555
chrono = { version = "0.4", features = ["serde"] }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Get started with the SDK in a few easy steps:
5858

5959
<div align='center'>
6060
<img src="https://img.shields.io/badge/macos-working-green?style=for-the-badge" alt=macos style="margin-bottom: 5px;"/>
61-
<img src="https://img.shields.io/badge/linux-mostly_working-yellow?style=for-the-badge" alt=linux style="margin-bottom: 5px;"/>
62-
<img src="https://img.shields.io/badge/windows-not_working-red?style=for-the-badge" alt=windows style="margin-bottom: 5px;"/>
61+
<img src="https://img.shields.io/badge/linux-working-green?style=for-the-badge" alt=linux style="margin-bottom: 5px;"/>
62+
<img src="https://img.shields.io/badge/windows-wip-yellow?style=for-the-badge" alt=windows style="margin-bottom: 5px;"/>
6363
</div>
6464

6565
##

microsandbox-portal/examples/repl.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use std::error::Error;
6262
#[tokio::main]
6363
async fn main() -> Result<(), Box<dyn Error>> {
6464
// Start the engines - this initializes all enabled engines
65-
let engine_handle = start_engines().await?;
65+
let _engine_handle = start_engines().await?;
6666
println!("✅ Engines started successfully");
6767

6868
// Example 1: Execute Python code in REPL
@@ -89,7 +89,7 @@ for i, fruit in enumerate(fruits):
8989
print(f"{i+1}. {fruit}")
9090
"#;
9191

92-
let result = engine_handle
92+
let result = _engine_handle
9393
.eval(python_code, Language::Python, "123", Some(60))
9494
.await?;
9595

@@ -147,7 +147,7 @@ fetchData().then(result => {
147147
console.log("Waiting for data...");
148148
"#;
149149

150-
let result = engine_handle
150+
let result = _engine_handle
151151
.eval(javascript_code, Language::Node, "123", Some(60))
152152
.await?;
153153

@@ -164,7 +164,7 @@ console.log("Waiting for data...");
164164

165165
// First execution - define a variable
166166
let python_step1 = "x = 10";
167-
let result1 = engine_handle
167+
let result1 = _engine_handle
168168
.eval(python_step1, Language::Python, "123", None)
169169
.await?;
170170
for line in result1 {
@@ -173,7 +173,7 @@ console.log("Waiting for data...");
173173

174174
// Second execution - use the variable defined in the first step
175175
let python_step2 = "print(f'The value of x is {x}')";
176-
let result2 = engine_handle
176+
let result2 = _engine_handle
177177
.eval(python_step2, Language::Python, "123", None)
178178
.await?;
179179
for line in result2 {
@@ -188,7 +188,7 @@ console.log("Waiting for data...");
188188

189189
// First execution - define a variable
190190
let nodejs_step1 = "const greeting = 'Hello from JavaScript!';";
191-
let result1 = engine_handle
191+
let result1 = _engine_handle
192192
.eval(nodejs_step1, Language::Node, "123", None)
193193
.await?;
194194
for line in result1 {
@@ -197,7 +197,7 @@ console.log("Waiting for data...");
197197

198198
// Second execution - use the variable defined in the first step
199199
let nodejs_step2 = "console.log(greeting);";
200-
let result2 = engine_handle
200+
let result2 = _engine_handle
201201
.eval(nodejs_step2, Language::Node, "123", None)
202202
.await?;
203203
for line in result2 {

microsandbox-portal/examples/repl_timer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@
4848
//! [Stderr] Execution timed out after 10 seconds
4949
//! ```
5050
51-
use microsandbox_portal::portal::repl::{start_engines, Language};
51+
use microsandbox_portal::portal::repl::start_engines;
52+
#[cfg(any(feature = "python", feature = "nodejs"))]
53+
use microsandbox_portal::portal::repl::Language;
5254
use std::error::Error;
5355

5456
/// Fixed timeout duration for all executions in this example
5557
const TIMEOUT_SECONDS: u64 = 10;
5658

5759
/// Print output lines from a REPL execution with a prefix
60+
#[cfg(any(feature = "python", feature = "nodejs"))]
5861
fn print_output(prefix: &str, lines: &[microsandbox_portal::portal::repl::Line]) {
5962
println!("{} execution result:", prefix);
6063
if lines.is_empty() {
@@ -70,7 +73,7 @@ fn print_output(prefix: &str, lines: &[microsandbox_portal::portal::repl::Line])
7073
#[tokio::main]
7174
async fn main() -> Result<(), Box<dyn Error>> {
7275
// Start the engines - this initializes all enabled engines
73-
let engine_handle = start_engines().await?;
76+
let _engine_handle = start_engines().await?;
7477
println!("✅ Engines started successfully\n");
7578
println!(
7679
"🕒 Running examples with {}-second timeout\n",
@@ -92,7 +95,7 @@ for i in range(1, 6):
9295
print("Python counting complete!")
9396
"#;
9497

95-
let result = engine_handle
98+
let result = _engine_handle
9699
.eval(
97100
python_normal,
98101
Language::Python,
@@ -119,7 +122,7 @@ while True:
119122
time.sleep(0.5) # Sleep for half a second
120123
"#;
121124

122-
let result = engine_handle
125+
let result = _engine_handle
123126
.eval(
124127
python_infinite,
125128
Language::Python,
@@ -152,7 +155,7 @@ for (let i = 1; i <= 5; i++) {
152155
console.log("Node.js counting complete!");
153156
"#;
154157

155-
let result = engine_handle
158+
let result = _engine_handle
156159
.eval(
157160
js_normal,
158161
Language::Node,
@@ -185,7 +188,7 @@ while (true) {
185188
}
186189
"#;
187190

188-
let result = engine_handle
191+
let result = _engine_handle
189192
.eval(
190193
js_infinite,
191194
Language::Node,

microsandbox-portal/examples/rpc_command.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//!
1111
//! # API Methods Demonstrated
1212
//!
13-
//! - `sandbox.command.execute`: Execute a command in a sandboxed environment
13+
//! - `sandbox.command.run`: Execute a command in a sandboxed environment
1414
//!
1515
//! # Running the Example
1616
//!
@@ -64,7 +64,7 @@ use reqwest::Client;
6464
use serde_json::{json, Value};
6565

6666
// Import the parameter types from the microsandbox-portal crate
67-
use microsandbox_portal::payload::{JsonRpcRequest, SandboxCommandExecuteParams, JSONRPC_VERSION};
67+
use microsandbox_portal::payload::{JsonRpcRequest, SandboxCommandRunParams, JSONRPC_VERSION};
6868

6969
//--------------------------------------------------------------------------------------------------
7070
// Functions
@@ -138,13 +138,13 @@ async fn main() -> Result<()> {
138138

139139
// Execute a simple 'ls' command using the typed params
140140
println!("\n📁 Running 'ls' command:");
141-
let ls_params = SandboxCommandExecuteParams {
141+
let ls_params = SandboxCommandRunParams {
142142
command: "ls".to_string(),
143143
args: vec!["-la".to_string()],
144144
timeout: Some(30), // Add a 30 second timeout
145145
};
146146

147-
let result = send_rpc_request(&client, "sandbox.command.execute", ls_params).await?;
147+
let result = send_rpc_request(&client, "sandbox.command.run", ls_params).await?;
148148

149149
// Extract command execution details
150150
let command = result
@@ -183,13 +183,13 @@ async fn main() -> Result<()> {
183183

184184
// Execute another command with environment variables using the typed params
185185
println!("\n🔄 Running 'echo' command:");
186-
let echo_params = SandboxCommandExecuteParams {
186+
let echo_params = SandboxCommandRunParams {
187187
command: "echo".to_string(),
188188
args: vec!["Hello from the sandbox!".to_string()],
189189
timeout: None, // No timeout needed for simple echo command
190190
};
191191

192-
let result = send_rpc_request(&client, "sandbox.command.execute", echo_params).await?;
192+
let result = send_rpc_request(&client, "sandbox.command.run", echo_params).await?;
193193

194194
// Extract command execution details
195195
let command = result
@@ -228,14 +228,14 @@ async fn main() -> Result<()> {
228228

229229
// Execute a command that will fail to demonstrate error handling
230230
println!("\n❌ Running a command that will fail:");
231-
let fail_params = SandboxCommandExecuteParams {
231+
let fail_params = SandboxCommandRunParams {
232232
command: "nonexistent_command".to_string(),
233233
args: vec![],
234234
timeout: Some(5), // Short timeout
235235
};
236236

237237
// This will likely fail, so handle the error case
238-
match send_rpc_request(&client, "sandbox.command.execute", fail_params).await {
238+
match send_rpc_request(&client, "sandbox.command.run", fail_params).await {
239239
Ok(result) => {
240240
// Still might get a result with error details
241241
let exit_code = result

microsandbox-portal/lib/handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing::debug;
77
use crate::{
88
error::PortalError,
99
payload::{
10-
JsonRpcError, JsonRpcRequest, JsonRpcResponse, SandboxCommandExecuteParams,
10+
JsonRpcError, JsonRpcRequest, JsonRpcResponse, SandboxCommandRunParams,
1111
SandboxReplRunParams, JSONRPC_VERSION,
1212
},
1313
portal::command::create_command_executor,
@@ -59,7 +59,7 @@ pub async fn json_rpc_handler(
5959
}
6060
}
6161
}
62-
"sandbox.command.execute" => {
62+
"sandbox.command.run" => {
6363
// Call the sandbox_command_run_impl function
6464
match sandbox_command_run_impl(state, request.params).await {
6565
Ok(result) => {
@@ -186,12 +186,12 @@ async fn sandbox_run_impl(_state: SharedState, params: Value) -> Result<Value, P
186186
Ok(result)
187187
}
188188

189-
/// Implementation for sandbox command execute method
189+
/// Implementation for sandbox command run method
190190
async fn sandbox_command_run_impl(state: SharedState, params: Value) -> Result<Value, PortalError> {
191-
debug!(?params, "Sandbox command execute method called");
191+
debug!(?params, "Sandbox command run method called");
192192

193193
// Deserialize parameters using the structured type
194-
let params: SandboxCommandExecuteParams = serde_json::from_value(params)
194+
let params: SandboxCommandRunParams = serde_json::from_value(params)
195195
.map_err(|e| PortalError::JsonRpc(format!("Invalid parameters: {}", e)))?;
196196

197197
// Get or initialize command executor handle

microsandbox-portal/lib/payload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub struct SandboxReplRunParams {
8282

8383
/// Request parameters for executing a shell command
8484
#[derive(Debug, Deserialize, Serialize)]
85-
pub struct SandboxCommandExecuteParams {
85+
pub struct SandboxCommandRunParams {
8686
/// Command to execute
8787
pub command: String,
8888

0 commit comments

Comments
 (0)