Skip to content

An open-source, faster Devin alternative

TypeScript

Fix Python SDK docs: replace broken async with Sandbox.create() examples

motatoes19c9d46cf526
diff --git a/docs/introduction.mdx b/docs/introduction.mdx
index 6b851ce8..a1cd14b2 100644
--- a/docs/introduction.mdx
+++ b/docs/introduction.mdx
@@ -56,11 +56,16 @@ await sandbox.kill();
```
```python Python
+import asyncio
from opensandbox import Sandbox
-async with Sandbox.create(template='base') as sandbox:
+async def main():
+ sandbox = await Sandbox.create(template='base')
result = await sandbox.commands.run('echo "Hello from OpenSandbox!"')
print(result.stdout) # Hello from OpenSandbox!
+ await sandbox.kill()
+
+asyncio.run(main())
```
</CodeGroup>
diff --git a/docs/quickstart.mdx b/docs/quickstart.mdx
index 17711c60..3c9fb96b 100644
--- a/docs/quickstart.mdx
+++ b/docs/quickstart.mdx
@@ -115,10 +115,16 @@ await sandbox.kill();
```python Python
await sandbox.kill()
-# Or use the context manager for automatic cleanup:
-async with Sandbox.create() as sandbox:
- # sandbox is automatically killed when the block exits
- result = await sandbox.commands.run('whoami')
+# Or use try/finally for automatic cleanup:
+async def main():
+ sandbox = await Sandbox.create()
+ try:
+ result = await sandbox.commands.run('whoami')
+ finally:
+ await sandbox.kill()
+ await sandbox.close()
+
+asyncio.run(main())
```
</CodeGroup>
diff --git a/docs/sdks/python/overview.mdx b/docs/sdks/python/overview.mdx
index 80f95d26..e2a0892d 100644
--- a/docs/sdks/python/overview.mdx
+++ b/docs/sdks/python/overview.mdx
@@ -32,21 +32,25 @@ import asyncio
from opensandbox import Sandbox
async def main():
- async with Sandbox.create(template='base') as sandbox:
- # Run a command
- result = await sandbox.commands.run('python3 --version')
- print(result.stdout)
+ sandbox = await Sandbox.create(template='base')
- # Work with files
- await sandbox.files.write('/app/main.py', 'print("hello")')
- output = await sandbox.commands.run('python3 /app/main.py')
- print(output.stdout) # hello
+ # Run a command
+ result = await sandbox.commands.run('python3 --version')
+ print(result.stdout)
+
+ # Work with files
+ await sandbox.files.write('/app/main.py', 'print("hello")')
+ output = await sandbox.commands.run('python3 /app/main.py')
+ print(output.stdout) # hello
+
+ await sandbox.kill()
+ await sandbox.close()
asyncio.run(main())
```
<Note>
- All SDK operations are async. Use `async with` for automatic cleanup, or call `await sandbox.kill()` manually.
+ All SDK operations are async. Call `await sandbox.kill()` to stop the sandbox and `await sandbox.close()` to clean up the HTTP client.
</Note>
## Exports
diff --git a/docs/sdks/python/sandbox.mdx b/docs/sdks/python/sandbox.mdx
index ecf05e15..55a0b542 100644
--- a/docs/sdks/python/sandbox.mdx
+++ b/docs/sdks/python/sandbox.mdx
@@ -43,15 +43,13 @@ Creates a new sandbox and returns a connected `Sandbox` instance.
**Returns:** `Sandbox`
-## Async Context Manager
-
-The recommended way to use sandboxes in Python — the sandbox is automatically killed when the block exits:
+## Usage
```python
-async with Sandbox.create(template='base') as sandbox:
- result = await sandbox.commands.run('echo "hello"')
- print(result.stdout)
-# sandbox is automatically killed here
+sandbox = await Sandbox.create(template='base')
+result = await sandbox.commands.run('echo "hello"')
+print(result.stdout)
+await sandbox.kill()
```
## Connecting to an Existing Sandbox
diff --git a/docs/sdks/python/templates.mdx b/docs/sdks/python/templates.mdx
index 6eb8c5e5..bd70b3dc 100644
--- a/docs/sdks/python/templates.mdx
+++ b/docs/sdks/python/templates.mdx
@@ -99,9 +99,10 @@ Deletes a template by name.
Once built, pass the template name when creating a sandbox:
```python
-async with Sandbox.create(template='python-ml') as sandbox:
- result = await sandbox.commands.run(
- 'python3 -c "import numpy; print(numpy.__version__)"'
- )
- print(result.stdout) # 1.24.0
+sandbox = await Sandbox.create(template='python-ml')
+result = await sandbox.commands.run(
+ 'python3 -c "import numpy; print(numpy.__version__)"'
+)
+print(result.stdout) # 1.24.0
+await sandbox.kill()
```