Skip to content

Commit 115ad76

Browse files
committed
📝docs: refactor and update
1 parent 71901a3 commit 115ad76

23 files changed

+812
-236
lines changed

docs/api.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/api/codebox.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# CodeBox Class API Reference
2+
3+
## Constructor
4+
5+
```python
6+
CodeBox(
7+
session_id: str | None = None,
8+
api_key: str | Literal["local", "docker"] | None = None,
9+
factory_id: str | Literal["default"] | None = None,
10+
)
11+
```
12+
13+
## Core Methods
14+
15+
### Code Execution
16+
17+
- `exec(code: str, kernel: Literal["ipython", "bash"] = "ipython") -> ExecResult`
18+
- `aexec(code: str, kernel: Literal["ipython", "bash"] = "ipython") -> ExecResult`
19+
20+
### File Operations
21+
22+
- `upload(remote_file_path: str, content: Union[BinaryIO, bytes, str]) -> RemoteFile`
23+
- `download(remote_file_path: str) -> RemoteFile`
24+
- `list_files() -> List[RemoteFile]`
25+
26+
### Package Management
27+
28+
- `install(*packages: str) -> str`
29+
- `ainstall(*packages: str) -> str`
30+
31+
### Health Checks
32+
33+
- `healthcheck() -> Literal["healthy", "error"]`
34+
- `ahealthcheck() -> Literal["healthy", "error"]`
35+
36+
## Deprecated Methods
37+
38+
The following methods are deprecated and should be replaced with their newer alternatives:
39+
40+
- `run()` → Use `exec()` instead
41+
- `arun()` → Use `aexec()` instead
42+
- `status()` → Use `healthcheck()` instead
43+
- `astatus()` → Use `ahealthcheck()` instead

docs/api/exceptions.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Exceptions API Reference
2+
3+
## CodeBoxError
4+
5+
The main exception class for CodeBox-related errors. Provides detailed context about API errors.
6+
7+
### Attributes:
8+
9+
- `status_code`: HTTP status code from the API response
10+
- `response_json`: Parsed JSON body from the response
11+
- `headers`: Response headers
12+
13+
### Common Error Cases
14+
15+
```python
16+
from codeboxapi import CodeBox, CodeBoxError
17+
18+
try:
19+
with CodeBox() as codebox:
20+
codebox.exec("invalid python code")
21+
except CodeBoxError as e:
22+
print(f"Error {e.status_code}: {e.response_json}")
23+
```
24+
25+
### Error Types
26+
1. Authentication Errors (401)
27+
2. Rate Limit Errors (429)
28+
3. Execution Errors (400)
29+
4. Server Errors (500)

docs/api/settings.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Settings API Reference
2+
3+
## CodeBoxSettings
4+
5+
The `CodeBoxSettings` class manages the configuration for the CodeBox client. It inherits from Pydantic's `BaseSettings` class and loads values from environment variables.
6+
7+
### Environment Variables and Settings
8+
9+
#### API Settings
10+
- `CODEBOX_API_KEY: str | None = None`
11+
Your API key for authentication
12+
- `CODEBOX_BASE_URL: str = "https://codeboxapi.com/api/v2"`
13+
Base URL for the API
14+
- `CODEBOX_TIMEOUT: int = 20`
15+
Request timeout in seconds
16+
17+
#### Additional Settings
18+
- `CODEBOX_FACTORY_ID: str = "default"`
19+
Custom Docker image or environment
20+
- `CODEBOX_SESSION_ID: str | None = None`
21+
Custom session identifier
22+
23+
#### Logging Settings
24+
- `VERBOSE: bool = False`
25+
Determines if verbose logging is enabled
26+
- `SHOW_INFO: bool = True`
27+
Determines if information-level logging is enabled
28+
29+
### Usage
30+
31+
```python
32+
from codeboxapi import CodeBox
33+
# Using environment variables
34+
codebox = CodeBox()
35+
# Or explicitly in code
36+
codebox = CodeBox(
37+
api_key="your-api-key",
38+
base_url="https://custom-url.com/api/v1",
39+
timeout=30
40+
)
41+
```

docs/concepts/architecture.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Architecture Overview
2+
- [REST API](https://codeboxapi.com/docs)
3+
### Core Components
4+
- [Github Repo](https://github.com/shroominic/codebox-api)
5+
1. **Base Layer**
6+
- Abstract `BaseBox` class
7+
- Core execution interface
8+
- Session management
9+
- Resource handling
10+
2. **Implementation Layer**
11+
- `LocalBox`: Local development environment
12+
- `DockerBox`: Containerized execution
13+
- `RemoteBox`: Cloud execution service
14+
3. **API Layer**
15+
- REST API interface
16+
- Async/Sync operations
17+
- File management
18+
- Package handling
19+
## Why is Sandboxing Important?
20+
Security is critical when deploying LLM Agents in production:
21+
- 🛡️ **Malicious Code Protection**: Isolated and secure execution
22+
- 🔐 **Injection Prevention**: Mitigation of prompt injection attacks
23+
- 🏰 **System Isolation**: No host system access
24+
- 📊 **Resource Control**: Memory and CPU limits
25+
## How It Works
26+
CodeBox uses a three-tier architecture:
27+
1. **API Layer**
28+
- REST API for service interaction
29+
- API key authentication
30+
- Sync/Async operation support
31+
2. **Container Layer**
32+
- Hardened Docker containers
33+
- Complete host system isolation
34+
- Automatic resource management
35+
3. **Storage Layer**
36+
- Persistent file system
37+
- Dependency management
38+
- Package caching

docs/concepts.md renamed to docs/concepts/components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ Custom exception class raised when there is an error response from the API. It i
7272
- Response JSON body
7373
- Response headers
7474

75-
This provides an easy way to handle errors with additional context.
75+
This provides an easy way to handle errors with additional context.

docs/concepts/data_structures.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Data Structures
2+
3+
## Core Types
4+
5+
### RemoteFile
6+
Represents a file in the CodeBox environment:
7+
```python
8+
class RemoteFile:
9+
path: str # File path in CodeBox
10+
remote: CodeBox # Associated CodeBox instance
11+
_size: int # File size in bytes
12+
_content: bytes # File content
13+
```
14+
15+
### Methods:
16+
- `get_content():` Get file contents
17+
- `aget_content():` Async get contents
18+
- `save(path):` Save to local path
19+
- `asave(path):` Async save to local path
20+
21+
### ExecChunk
22+
Represents an execution output chunk:
23+
24+
```python
25+
class ExecChunk:
26+
type: Literal["txt", "img", "err"] # Output type
27+
content: str # Chunk content
28+
```
29+
30+
### Types:
31+
- `txt:` Text output
32+
- `img:` Base64 encoded image
33+
- `err:` Error message
34+
35+
### ExecResult
36+
Complete execution result:
37+
```python
38+
class ExecResult:
39+
chunks: List[ExecChunk] # List of output chunks
40+
```
41+
### Properties:
42+
- `text:` Combined text output
43+
- `images:` List of image outputs
44+
- `errors:` List of error messages
45+
### Usage Examples
46+
```python
47+
# File handling
48+
with CodeBox() as codebox:
49+
# Upload and get file
50+
file = codebox.upload("test.txt", "content")
51+
content = file.get_content()
52+
53+
# Execute code and handle result
54+
result = codebox.exec("print('hello')")
55+
print(result.text) # Text output
56+
print(result.errors) # Any errors
57+
```

docs/concepts/implementations.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# CodeBox Implementations
2+
3+
## Implementation Overview
4+
5+
### LocalBox
6+
- **Usage**: Local development and testing
7+
- **Requirements**: jupyter-kernel-gateway, ipython
8+
- **Configuration**: `api_key="local"`
9+
- **Advantages**:
10+
- Rapid development
11+
- No external dependencies
12+
- Direct local environment access
13+
- Fast execution for development
14+
- **Limitations**:
15+
- No isolation
16+
- Development only
17+
- Local system resources
18+
19+
### DockerBox
20+
- **Usage**: Isolated testing
21+
- **Requirements**: Docker installation
22+
- **Configuration**: `api_key="docker"`
23+
- **Advantages**:
24+
- Local isolation
25+
- Consistent environment
26+
- No API costs
27+
- Custom image support
28+
- **Limitations**:
29+
- Requires Docker
30+
- Local resource constraints
31+
- Additional setup needed
32+
33+
### RemoteBox
34+
- **Usage**: Production, scaling and cloud deployment
35+
- **Requirements**:
36+
- Valid API key
37+
- Internet connection
38+
- **Configuration**:
39+
```python
40+
codebox = CodeBox(api_key="your-api-key")
41+
```
42+
- **Key Features**:
43+
- REST API integration
44+
- Automatic session management
45+
- Cloud-based file storage
46+
- Managed package installation
47+
- Resource usage monitoring
48+
- **Best for**:
49+
- Production deployments
50+
- Scalable applications
51+
- Team collaborations
52+
53+
## Implementation Comparison
54+
55+
| Feature | RemoteBox | LocalBox | DockerBox |
56+
|---------|-----------|----------|------------|
57+
| Isolation | Full | Minimal | Full |
58+
| Setup Complexity | Low | Medium | High |
59+
| Resource Scaling | Yes | No | Limited |
60+
| Internet Required | Yes | No | No |
61+
| Cost | API Usage | Free | Free |

docs/examples.md

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

0 commit comments

Comments
 (0)