Code Sandbox Capabilities
Running programs and executing language code in the sandbox
You can run your code inside the Lybic desktop sandbox without worrying about affecting physical environments. This guide explains the sandbox’s code execution capabilities and how to run code safely within Lybic sandboxes.
Think of the Lybic sandbox as a full operating system where you can write and execute any code.
Language Support
The following programming languages are pre-installed in the Lybic sandbox:
| Language & Version | Linux Support | Windows Support | Primary Commands | Notes |
|---|---|---|---|---|
| Python 3.12 | ✅ | ❌ | python python3 python3.12 pip3 uv | System package, supports python -m venv to create virtual environments; install dependencies with pip3 install packagename --break-system-packages |
| Python 3.13 | ❌ | ✅ | python pip uv conda-env conda | Anaconda / uv |
| Node.js v24 | ✅ | ✅ | node npm npx corepack | |
| Golang 1.25 | ✅ | ✅ | go | CGO_ENABLE=1 in Linux sandbox |
| Rustlang 1.92 | ✅ | ✅ | cargo rustc rustdoc rustfmt rust-analyzer rust-gdb rust-lldb | |
| Gcc 13 | ✅ | ❌ | gcc g++ | |
| MSVC 14.50 (2025) | ❌ | ✅ | cl link | Manually activate via C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvars64.bat |
| Batch Scripts | ❌ | ✅ | cmd | |
| PowerShell 5.1 | ❌ | ✅ | powershell | |
| Bash 5.1 | ✅ | ❌ | bash | |
| Ash 1.20 | ❌ | ✅ | ash | Provided via Git |
You can invoke arbitrary code inside the sandbox using the execSandboxProcess API provided by the Lybic SDK. By combining inputs you can execute code in different programming languages. The API accepts command line arguments, environment variables, stdin, and returns stdout, stderr, and exit codes.
Running Sandbox Programs
Use the execSandboxProcess API to run arbitrary programs inside the sandbox. Below are examples for various language SDKs:
Basic Usage
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "ls",
"args": ["-la", "/home"],
"workingDirectory": "/home"
}'import asyncio
import base64
from Lybic import LybicClient, LybicAuth
async def main():
async with LybicClient(
LybicAuth(
org_id="ORG-xxxx",
api_key="lysk-xxxxxxxxxxx",
endpoint="https://api.Lybic.cn/"
)
) as client:
result = await client.sandbox.execute_process(
"SBX-xxxx",
executable="/bin/ls",
args=["-la", "/home"],
workingDirectory="/home"
)
print(f"Exit Code: {result.exitCode}")
print(f"Output: {base64.b64decode(result.stdoutBase64 or '').decode()}")
if __name__ == "__main__":
asyncio.run(main())import { LybicClient } from '@Lybic/core'
const Lybic = new LybicClient({
baseUrl: 'https://api.Lybic.cn',
orgId: 'ORG-xxxx',
apiKey: 'lysk-your-api-key-here',
})
const result = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'ls',
args: ['-la', '/home'],
workingDirectory: '/home',
})
console.log('Exit Code:', result.data?.exitCode)
console.log('Output:', atob(result.data?.stdoutBase64 || ''))package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/Lybic/Lybic-sdk-go"
)
func main() {
ctx := context.Background()
client, _ := Lybic.NewClient(nil)
processDto := Lybic.SandboxProcessRequestDto{
Executable: "/bin/ls",
Args: []string{"-la", "/home"},
}
result, err := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto)
if err != nil {
fmt.Println("Error executing process:", err)
return
}
stdout, _ := base64.StdEncoding.DecodeString(result.StdoutBase64)
fmt.Printf("Exit Code: %d\n", result.ExitCode)
fmt.Printf("Output: %s\n", string(stdout))
}Request Parameters:
executable: Path or command name to execute (required)args: Array of command line arguments (optional)workingDirectory: Working directory (optional)stdinBase64: Base64-encoded stdin content (optional)
Sample Response:
{
"stdoutBase64": "dG90YWwgNAo...",
"stderrBase64": "",
"exitCode": 0
}Decode stdoutBase64 and stderrBase64 from Base64 to read the actual output.
Executing Programming Language Code
Python Code Execution
# Method 1: Execute Python code directly via stdin
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "python3",
"stdinBase64": "cHJpbnQoJ0hlbGxvLCBXb3JsZCEnKQ=="
}'
# Method 2: Run a Python file
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "python3",
"args": ["script.py"],
"workingDirectory": "/home/agent/project"
}'import asyncio
import base64
from Lybic import LybicClient, LybicAuth, dto
async def main():
async with LybicClient(
LybicAuth(
org_id="ORG-xxxx",
api_key="lysk-xxxxxxxxxxx",
endpoint="https://api.Lybic.cn/"
)
) as client:
# Method 1: Run Python code via stdin
code = "print('Hello, World!')"
stdin_data = base64.b64encode(code.encode()).decode()
result = await client.sandbox.execute_process(
"SBX-xxxx",
executable="python3",
stdinBase64=stdin_data
)
print(f"Output: {base64.b64decode(result.stdoutBase64 or '').decode()}")
# Method 2: Run a Python file
result = await client.sandbox.execute_process(
"SBX-xxxx",
executable="python3",
args=["script.py"],
workingDirectory="/home/agent/project"
)
print(f"Exit Code: {result.exitCode}")
if __name__ == "__main__":
asyncio.run(main())import { LybicClient } from '@Lybic/core'
const Lybic = new LybicClient({
baseUrl: 'https://api.Lybic.cn',
orgId: 'ORG-xxxx',
apiKey: 'lysk-your-api-key-here',
})
// Method 1: Run Python code via stdin
const code = "print('Hello, World!')"
const stdinBase64 = btoa(code)
const result1 = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'python3',
args: [],
stdinBase64: stdinBase64,
})
console.log('Output:', atob(result1.data?.stdoutBase64 || ''))
// Method 2: Run a Python file
const result2 = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'python3',
args: ['script.py'],
workingDirectory: '/home/agent/project',
})
console.log('Exit Code:', result2.data?.exitCode)package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/Lybic/Lybic-sdk-go"
)
func main() {
ctx := context.Background()
client, _ := Lybic.NewClient(nil)
// Method 1: Run Python code via stdin
code := "print('Hello, World!')"
stdinBase64 := base64.StdEncoding.EncodeToString([]byte(code))
processDto := Lybic.SandboxProcessRequestDto{
Executable: "python3",
Args: []string{},
StdinBase64: &stdinBase64,
}
result, _ := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto)
stdout, _ := base64.StdEncoding.DecodeString(result.StdoutBase64)
fmt.Printf("Output: %s\n", string(stdout))
// Method 2: Run a Python file
workDir := "/home/agent/project"
processDto2 := Lybic.SandboxProcessRequestDto{
Executable: "python3",
Args: []string{"script.py"},
WorkingDirectory: &workDir,
}
result2, _ := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto2)
fmt.Printf("Exit Code: %d\n", result2.ExitCode)
}Node.js Code Execution
# Run JavaScript code
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "node",
"args": ["-e", "console.log(\"Hello from Node.js\")"]
}'import asyncio
import base64
from Lybic import LybicClient, LybicAuth
async def main():
async with LybicClient(
LybicAuth(
org_id="ORG-xxxx",
api_key="lysk-xxxxxxxxxxx",
endpoint="https://api.Lybic.cn/"
)
) as client:
result = await client.sandbox.execute_process(
"SBX-xxxx",
executable="node",
args=["-e", "console.log('Hello from Node.js')"]
)
print(f"Output: {base64.b64decode(result.stdoutBase64 or '').decode()}")
if __name__ == "__main__":
asyncio.run(main())import { LybicClient } from '@Lybic/core'
const Lybic = new LybicClient({
baseUrl: 'https://api.Lybic.cn',
orgId: 'ORG-xxxx',
apiKey: 'lysk-your-api-key-here',
})
const result = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'node',
args: ['-e', 'console.log("Hello from Node.js")'],
})
console.log('Output:', atob(result.data?.stdoutBase64 || ''))package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/Lybic/Lybic-sdk-go"
)
func main() {
ctx := context.Background()
client, _ := Lybic.NewClient(nil)
processDto := Lybic.SandboxProcessRequestDto{
Executable: "node",
Args: []string{"-e", "console.log('Hello from Node.js')"},
}
result, _ := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto)
stdout, _ := base64.StdEncoding.DecodeString(result.StdoutBase64)
fmt.Printf("Output: %s\n", string(stdout))
}Go Code Execution
# Method 1: Run a Go file
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "go",
"args": ["run", "main.go"],
"workingDirectory": "/home/agent/project"
}'
# Method 2: Build and run
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "go",
"args": ["build", "-o", "app", "main.go"],
"workingDirectory": "/home/agent/project"
}'import asyncio
import base64
from Lybic import LybicClient, LybicAuth
async def main():
async with LybicClient(
LybicAuth(
org_id="ORG-xxxx",
api_key="lysk-xxxxxxxxxxx",
endpoint="https://api.Lybic.cn/"
)
) as client:
# Run a Go file
result = await client.sandbox.execute_process(
"SBX-xxxx",
executable="go",
args=["run", "main.go"],
workingDirectory="/home/agent/project"
)
print(f"Output: {base64.b64decode(result.stdoutBase64 or '').decode()}")
if __name__ == "__main__":
asyncio.run(main())import { LybicClient } from '@Lybic/core'
const Lybic = new LybicClient({
baseUrl: 'https://api.Lybic.cn',
orgId: 'ORG-xxxx',
apiKey: 'lysk-your-api-key-here',
})
// Run a Go file
const result = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'go',
args: ['run', 'main.go'],
workingDirectory: '/home/agent/project',
})
console.log('Output:', atob(result.data?.stdoutBase64 || ''))package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/Lybic/Lybic-sdk-go"
)
func main() {
ctx := context.Background()
client, _ := Lybic.NewClient(nil)
workDir := "/home/agent/project"
processDto := Lybic.SandboxProcessRequestDto{
Executable: "go",
Args: []string{"run", "main.go"},
WorkingDirectory: &workDir,
}
result, _ := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto)
stdout, _ := base64.StdEncoding.DecodeString(result.StdoutBase64)
fmt.Printf("Output: %s\n", string(stdout))
}Rust Code Execution
# Run a Cargo project
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "cargo",
"args": ["run"],
"workingDirectory": "/home/user/rust-project"
}'import asyncio
import base64
from Lybic import LybicClient, LybicAuth
async def main():
async with LybicClient(
LybicAuth(
org_id="ORG-xxxx",
api_key="lysk-xxxxxxxxxxx",
endpoint="https://api.Lybic.cn/"
)
) as client:
result = await client.sandbox.execute_process(
"SBX-xxxx",
executable="cargo",
args=["run"],
workingDirectory="/home/user/rust-project"
)
print(f"Output: {base64.b64decode(result.stdoutBase64 or '').decode()}")
if __name__ == "__main__":
asyncio.run(main())import { LybicClient } from '@Lybic/core'
const Lybic = new LybicClient({
baseUrl: 'https://api.Lybic.cn',
orgId: 'ORG-xxxx',
apiKey: 'lysk-your-api-key-here',
})
const result = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'cargo',
args: ['run'],
workingDirectory: '/home/user/rust-project',
})
console.log('Output:', atob(result.data?.stdoutBase64 || ''))package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/Lybic/Lybic-sdk-go"
)
func main() {
ctx := context.Background()
client, _ := Lybic.NewClient(nil)
workDir := "/home/agent/rust-project"
processDto := Lybic.SandboxProcessRequestDto{
Executable: "cargo",
Args: []string{"run"},
WorkingDirectory: &workDir,
}
result, _ := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto)
stdout, _ := base64.StdEncoding.DecodeString(result.StdoutBase64)
fmt.Printf("Output: %s\n", string(stdout))
}Passing Code Through Standard Input
# Pipe Python code via stdin
curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "sh",
"args": ["-c","echo \"print('Hello, World!')\" | python"]
}
'import asyncio
import base64
from Lybic import LybicClient, LybicAuth
async def main():
async with LybicClient(
LybicAuth(
org_id="ORG-xxxx",
api_key="lysk-xxxxxxxxxxx",
endpoint="https://api.Lybic.cn/"
)
) as client:
code = 'print("Hello, World!")'
stdin_data = base64.b64encode(code.encode()).decode()
result = await client.sandbox.execute_process(
"SBX-xxxx",
executable="python",
stdinBase64=stdin_data
)
print(f"Output: {base64.b64decode(result.stdoutBase64 or '').decode()}")
if __name__ == "__main__":
asyncio.run(main())import { LybicClient } from '@Lybic/core'
const Lybic = new LybicClient({
baseUrl: 'https://api.Lybic.cn',
orgId: 'ORG-xxxx',
apiKey: 'lysk-your-api-key-here',
})
const code = 'print("Hello, World!")'
const stdinBase64 = btoa(code)
const result = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'python',
stdinBase64: stdinBase64,
})
console.log('Output:', atob(result.data?.stdoutBase64 || ''))package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/Lybic/Lybic-sdk-go"
)
func main() {
ctx := context.Background()
client, _ := Lybic.NewClient(nil)
code := `print("Hello, World!")`
stdinBase64 := base64.StdEncoding.EncodeToString([]byte(code))
processDto := Lybic.SandboxProcessRequestDto{
Executable: "python",
StdinBase64: &stdinBase64,
}
result, _ := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto)
stdout, _ := base64.StdEncoding.DecodeString(result.StdoutBase64)
fmt.Printf("Output: %s\n", string(stdout))
}Notes
- All stdin/stdout data is Base64-encoded to ensure binary-safe transmission.
- Sandbox processes have timeout limits and will be terminated if they exceed them.
- Working directories must exist inside the sandbox; otherwise, execution fails.
- Use the
exitCodeto determine whether a process succeeded (0means success).