Welcome to CodeBoxAPI
Unleash the Power of Your LLM
Applications with CodeBoxAPI
Simplify your project deployment with secure
Python execution in the cloud
and hassle-free file management.
from codeboxapi import CodeBox
codebox = CodeBox()
result = codebox.exec("""
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.savefig('graph.png')
""")
print(result)
graph = codebox.download("graph.png")
know more βββ
# Potentially risky code in a not isolated environment
from codeboxapi import CodeBox
codebox = CodeBox()
# this would expose e.g. your OpenAI API key
backend_secrets = codebox.exec("import os; print(os.environ)")
# this would delete the entire system
codebox.exec("os.system('rm -rf /')")
# When using codeboxapi, nothing bad happens, since it's just a sandbox
Sandboxed Environment
Enjoy peace of mind knowing their code runs in a safe, sandboxed environment. This security allows you to experiment and develop confidently, without concerns about compromising their main system's integrity or exposing it to vulnerabilities.
Efficient Workflow
Experience a smooth and efficient workflow when handling file operations, significantly reducing the time and effort required for data management. This simplicity allows you to focus more on core development tasks, enhancing overall productivity and satisfaction.
from codeboxapi import CodeBox
codebox = CodeBox()
# Upload a CSV file
codebox.upload("data.csv", "id,name\n1,Anna\n2,Bob\n3,Charlie")
# Process data and generate a graph
codebox.exec("""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('data.csv')
df['name_length'] = df['name'].str.len()
df.plot(x='name', y='name_length', kind='bar')
plt.savefig('graph.png')
""")
# Lookup files
print("Files:", [file for file in codebox.list_files()])
# Download files
graph = codebox.download("graph.png")
print(f"Graph downloaded: {graph.size} bytes")
import asyncio
from codeboxapi import CodeBox
codebox = CodeBox()
async def stream_output():
async for chunk in codebox.astream_exec(
"for i in range(5):\n"
" print(f'Count: {i}')\n"
" await asyncio.sleep(1)",
):
print(f"Received: {chunk.text}")
asyncio.run(stream_output())
Asynchronous Streaming Execution
Experience real-time interaction with your code execution through asynchronous streaming. The `astream_exec` method allows you to receive and process output as it's generated, enabling more responsive and efficient applications, especially for long-running or data-intensive tasks.
Get started
Install:
pip install codeboxapi
Add environment variable:
CODEBOX_API_KEY=sk-***************
Try it out:
from codeboxapi import CodeBox
codebox = CodeBox()
codebox.exec("a = 'Hello'")
codebox.exec("b = 'World!'")
# variables will be preserved between executions
result = codebox.exec("print(a + ', ' + b)")
print(result.text)
# Hello, World!