Skip to content

Commit 9ed87a9

Browse files
committed
refactor: remove metrics functionality and simplify sandbox lifecycle
BREAKING CHANGE: Removed metrics functionality from Python and Rust SDKs - Removed metrics.py and related functionality from Python SDK - Removed metrics.rs and related functionality from Rust SDK - Simplified sandbox lifecycle management in both SDKs - Updated dotenv loading to be more resilient - Removed metrics examples and documentation - Updated dependencies in Rust SDK - Simplified error handling and command execution
1 parent 84b8eb1 commit 9ed87a9

File tree

23 files changed

+770
-1637
lines changed

23 files changed

+770
-1637
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,15 @@ npm install microsandbox
8585
pip install microsandbox
8686
```
8787

88-
<!--
8988
##### Rust
9089

9190
```sh
9291
cargo add microsandbox
9392
```
94-
-->
9593

9694
> [!NOTE]
9795
> There are [SDKs](./sdk) for other languages as well! Join us in expanding support for your favorite language.
96+
9897
<!--
9998
>
10099
> <div align="left">
@@ -167,7 +166,6 @@ async def main():
167166
asyncio.run(main())
168167
```
169168

170-
<!--
171169
##### Rust
172170

173171
```rs
@@ -187,7 +185,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
187185
Ok(())
188186
}
189187
```
190-
-->
191188

192189
> [!NOTE]
193190
>

sdk/python/README.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,6 @@ async def main():
6868
asyncio.run(main())
6969
```
7070

71-
### Retrieving Sandbox Metrics
72-
73-
```python
74-
import asyncio
75-
from microsandbox import PythonSandbox
76-
77-
async def main():
78-
async with PythonSandbox.create() as sandbox:
79-
# Get current sandbox metrics
80-
metrics = await sandbox.metrics.get()
81-
82-
# Access specific metrics
83-
print(f"Sandbox running: {metrics.running}")
84-
print(f"CPU usage: {metrics.cpu_usage:.2f}%")
85-
print(f"Memory usage: {metrics.memory_usage_mb:.2f} MB")
86-
print(f"Disk usage: {metrics.disk_usage_mb:.2f} MB")
87-
88-
# Access all raw metrics data
89-
print(f"Raw metrics: {metrics.raw_data}")
90-
91-
# Monitor sandbox performance over time
92-
for _ in range(5):
93-
metrics = await sandbox.metrics.get()
94-
print(f"CPU: {metrics.cpu_usage:.2f}%, Memory: {metrics.memory_usage_mb:.2f} MB")
95-
await asyncio.sleep(1)
96-
97-
asyncio.run(main())
98-
```
99-
10071
## Requirements
10172

10273
- Python 3.8+
@@ -115,7 +86,6 @@ Check out the [examples directory](./examples) for sample scripts that demonstra
11586
- Create and use sandboxes
11687
- Run code in sandbox environments
11788
- Execute shell commands in the sandbox
118-
- Monitor sandbox metrics and resource usage
11989
- Handle execution output and error handling
12090

12191
## License

sdk/python/examples/metrics.py

Lines changed: 0 additions & 144 deletions
This file was deleted.

sdk/python/microsandbox/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from .command import Command
1111
from .command_execution import CommandExecution
1212
from .execution import Execution
13-
from .metrics import Metrics, SandboxMetrics
1413
from .node_sandbox import NodeSandbox
1514
from .python_sandbox import PythonSandbox
1615

sdk/python/microsandbox/base_sandbox.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ def __init__(
4040
name: Optional name for the sandbox. If not provided, a random name will be generated.
4141
api_key: API key for Microsandbox server authentication. If not provided, it will be read from MSB_API_KEY environment variable.
4242
"""
43-
load_dotenv()
43+
# Only try to load .env if MSB_API_KEY is not already set
44+
if "MSB_API_KEY" not in os.environ:
45+
# Ignore errors if .env file doesn't exist
46+
try:
47+
load_dotenv()
48+
except Exception:
49+
pass
4450

4551
self._server_url = server_url or os.environ.get(
4652
"MSB_SERVER_URL", "http://127.0.0.1:5555"
@@ -82,6 +88,14 @@ async def create(
8288
Returns:
8389
An instance of the sandbox ready for use
8490
"""
91+
# Only try to load .env if MSB_API_KEY is not already set
92+
if "MSB_API_KEY" not in os.environ:
93+
# Ignore errors if .env file doesn't exist
94+
try:
95+
load_dotenv()
96+
except Exception:
97+
pass
98+
8599
sandbox = cls(
86100
server_url=server_url,
87101
namespace=namespace,

0 commit comments

Comments
 (0)